Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Top 19 Linux OS Commands Every Programmer Should Know in 2022-23

Posted on October 5, 2022

Top 19 Linux OS Commands Every Programmer Should Know in 2022-23

 

 

1) cd – navigate

 

cd command is used for navigating inside the directories inside the linux os system.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Go to "directory1" folder
cd directory1
 
# Go to "directory1" and in this folder go to "subdir1"
cd directory1/subdir1
 
# Go to ".ssh" in the root directory
cd ~/.ssh
 
# Go to the parent directory
cd ..
 
# Go two directories up
cd ../..

 

 

Here we have the series of commands to go to the nested or subdirectories. And we have the command to go to the parent directory.

 

 

2) ls – list files

 

 

This command is to list out the different files available inside the operating system.

 

 

1
2
3
4
5
6
# Listfiles
ls
# List files in a vertical list with more details
ls -l
# List files in the "dir1" folder
ls -l dir1

 

 

Here if you want to list out all the files in a vertical manner you need to add the -l flag after the command

 

And also we are adding the directory name dir1 after this command to list out the files of dir1

 

 

3) nano/vim

 

This command is used to edit files inside the linux os system. Both nano and vim are text editors in linux os system.

 

1
2
3
4
# Open yourfile.txt with nano
nano yourfile. txt
# Open yourfile.txt with vim
vim yourfile. txt

 

Here the syntax of the command is very simple. Just type the nano or vim followed by filename to open the file inside the editor to edit files.

 

 

4) pwd – Display current directory

 

This command is to display the current working directory where you are developing the current application. The command is very simple you just need to write pwd

 

1
pwd

 

 

5) clear (clear the terminal)

 

This command from the name itself is used to clear out the terminal inside the linux os system. The command are as follows

 

1
clear

 

 

6) cat (Output Content of File in Console)

 

This command is used to print out the contents of the file using the filename provided as argument. The command is as follows

 

1
2
3
4
5
# print the content of .htaccess
cat .htaccess
 
# print the content of index.php in the httpdocs directory
cat httpdocs/index.php

 

Here you can see that we are opening the content of the files using the filename as well.

 

 

7) Sudo (Run Commands as Administrator)

 

This command is also used to execute all the commands as an administrator. Sometimes administrator rights are required for certain operations. For this reason this command is very important.

 

1
2
3
4
5
6
7
8
# Print content of the .htaccess (with administrator permissions)
sudo cat .htaccess
 
# Go to dir2
sudo cd dir2
 
# Edit .htaccess
sudo nano .htaccess

 

 

8) grep — filter output (Search within a file)

 

This command is used to search a specific term in long files of long sizes. This command is very much powerful whenever you want to do filtering or searching of a word within a text file.

 

 

1
2
3
4
5
6
7
8
# Get all lines with "AddType" from .htaccess
grep AddType .htaccess
 
# get all lines with "AddType" from the application mime-type
grep "AddType application/.*" .htaccess
 
# Alternative: Combine the cat and grep command with a pipe
cat .htaccess | grep AddType

 

 

8) history (Show recent commands)

 

This command is useful in linux os system to list out all the recent commands which is executed by the user. The list will be vertical list and you can see all your commands in the history.

 

1
history

 

 

8) man (Show documentation or help page)

 

This command is useful in printing out the help page or documentation about different topics inside the terminal. The command syntax is very simple which are shown as follows

 

1
2
3
4
5
6
7
8
# manual for ls
man ls
 
# manual for wget
man wget
 
# manual for the pthread function (c, c++)
man pthread

 

 

9) Wget (Downloads Files From Internet)

 

This command is very useful in downloading any file from the internet to local disk straight from terminal in linux operating system. The syntax of the command is very simple which are as follows you write wget followed by the url of the file to download

 

1
2
# download the thumbnail of this post
wget https://webdeasy.de/wp-content/uploads/2021/04/linux-commands.jpg

 

 

10) mkdir (Creates New folder or Directory)

 

This command is very useful in creating new folders or directories inside the linux operating system. The syntax of the command is very easy. Just write mkdir followed by the name of the directory

 

1
2
# creates new directory
mkdir samplefolder

 

 

11) Touch (Creates New Files)

 

This command is very useful in creating new files if they don’t exist in the file system. The syntax is very useful just write touch followed by the name of the file to create

 

1
2
3
4
5
# create file phpinfo.php (if the file does not exist)
touch phpinfo.php
 
# update timstamp of phpinfo.php (if the file exists)
touch phpinfo.php

 

 

12) du (Calculate File & Directory Size)

 

This command is very useful in calculating the size of the files and directories and printing them inside terminal in linux operating system. The syntax of the command is as follows

 

1
2
3
4
5
6
7
8
9
10
11
# size of the htaccess in bytes. output e.g. 12 .htaccess
du .htaccess
 
# size of the htaccess (-h = human readable). output e.g. 12K .htaccess
du -h .htaccess
 
# size of EVERY SINGLE file inside the httpdocs directory (bad :c)
du httpdocs/
 
# size of the httpdocs directory (-s = summarize, -h = human readable). output e.g. 876M httpdocs/
du -sh httpdocs/

 

 

13) mv (Moving or Rename Files)

 

This command is very useful in moving files from location to another location and also renaming multiple files inside linux operating system. The Syntax of the command is very simple which is shown below

 

1
2
3
4
5
6
7
8
# rename file1.txt to file2.txt
mv file1.txt file2.txt
 
# rename file1.txt to file2.txt (in dir1 folder)
mv dir1/file1.txt dir1/file2.txt
 
# move file1.txt to httpdocs folder
mv file1.txt httpdocs

 

 

14) mv (Moving or Rename Files)

 

This command is very useful in moving files from location to another location and also renaming multiple files inside linux operating system. The Syntax of the command is very simple which is shown below

 

1
2
3
4
5
6
7
8
# rename file1.txt to file2.txt
mv file1.txt file2.txt
 
# rename file1.txt to file2.txt (in dir1 folder)
mv dir1/file1.txt dir1/file2.txt
 
# move file1.txt to httpdocs folder
mv file1.txt httpdocs

 

 

15) cp – copy file/directory

 

This command is very useful in copying multiple files & directories from location to another location. The Syntax of the command is very simple which is shown below

 

1
2
3
4
5
6
7
8
# copy file1.txt to file1-copy.txt
cp file1.txt file1-copy.txt
 
# copy httpdocs directory to httpdocs_BAK directory
cp -R httpdocs/ httpdocs_BAK
 
# copy httpdocs directory to httpdocs_BAK directory in the parents directory
cp -R httpdocs/ ../httpdocs_BAK

 

 

16) rm – delete file/directory

 

This command is very useful in deleting or removing multiple files & directories from file system and shifting to trash or recyclebin or removing it permanently. The Syntax of the command is very simple which is shown below

 

1
2
3
4
5
# remove file1.txt
rm file1.txt
 
# remove BAK directory
rm BAK/ -R

 

 

17) tar – pack/unpack archives

 

This command is very useful in extracting the contents from zip files or archives files. .tar files are similar .zip files in windows. This commands let you pack or unpack .tar archives files. The syntax of the command is shown below

 

1
2
3
4
5
# pack httpdocs into archive.tgz
tar -czf archive.tgz httpdocs
 
# unpack archive.tgz into the current directory
tar -xvzf archive.tgz

 

 

18) chmod (Adjust Files Rights & Levels)

 

This command is very useful in adjusting the files and rights of a particular file whether it is readable or writable or both. You can check the rights and levels using this command for a particular file

 

1
2
3
4
5
# all permissions for all files and directories in this directory (don't use this in public! e.g. webservers)
chmod 777 * -R
 
# set default permissions (good solution :))
chmod 755 .htaccess

 

 

19) chown (Customize owner/group)

 

This command is very useful in adjusting the owner group of a particular files or directory.

 

1
2
3
4
5
# set the owner to user1 and the group psaserv to file1.txt
chown user1:psaserv file1.txt
 
# set the owner and group root to the httpdocs directory and all files and directories in it
chown root:root httpdocs -R

 

Recent Posts

  • React.js Twitter API Tutorial to Embed Profile & Timeline, Hashtags of User in Browser Using Javascript
  • Android Java Tutorial to Change Styles & Visibility of System Bars (Top, Action & Status) Full Example
  • Android Java Project to Display & Play Audio Files From Storage inside ListView Using MediaPlayer Class
  • Android Java Project to Build MP4 Video to MP3 Audio Converter Using MediaMuxer Class
  • Android Java Project to Merge Multiple PDF Documents From Gallery Using iTextPDF Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme