Linux‎ > ‎

Basic Linux Commands



Some Useful Linux Commands

File Commands  
S. No.
shell Command
1 Directory listing  ls
2 Formatted listing with hidden files  ls -al 
3 Change directory to dirname  cd dirname
4 Change to home  cd
5 Show current directory pwd
6 Create a directory dirname mkdir dirname 
7 Delete filename  rm filename
8 Delete directory dirname rm -r dirname
9 Force remove file  rm -f file 
10 Force remove directory dirname rm -rf dirname 
11 Copy file1 to file2  cp file1 file2 
12 Copy dir1 to dir2; create dir2 if it doesn't exist   cp -r dir1 dir2 
13 Rename or move file1 to file2 if file2 is an existing directory, moves file1 into  directory file2 mv file1 file2 
14 Create symbolic link linkname to file   ln -s file linkname 
15 Create or update filename touch filename
16 Places standard input into filename cat > filename
17 Output the contents of filename more filename
18 Output the first 10 lines of filename head filename 
19 Output the last 10 lines of filename tail filename 
20 Output the contents of filename as it  grows, starting with the last 10 lines   tail -f filename
21    
Taking count of total numbers of file in a directory
ls -1 | wc -l




System Info  



1 Show the current date and time  date
2 Show this month's calendar  cal 
3 Show current uptime  uptime
4 Display who is online  finger
5 Who you are logged in as  whoami
6 Display information about user finger user 
7 Show kernel information  uname -a 
8 Cpu information  cat /proc/cpuinfo 
9 Memory information  cat /proc/meminfo 
10 Show the manual for command  man command 
11 Show disk usage  df
12 Show directory space usage  du 
13 Show memory and swap usage  free
14 Show possible locations of app  whereis app 
15 Show which app will be run by default   which app 







Compression (zip)



1 Create a tar named  file.tar containing files  tar cf file.tar files 
2 Extract the files from file.tar  tar xf file.tar 
3 Create a tar with  Gzip compression  tar czf file.tar.gz files 
4 Extract a tar using Gzip  tar xzf file.tar.gz 
5 Create a tar with Bzip2  compression  tar cjf file.tar.bz2 
6 Extract a tar using Bzip2  tar xjf file.tar.bz2 
7 Compresses file and renames it to  file.gz  gzip file 
8 Decompresses file.gz back to  file   gzip -d file.gz 







Network  



1 ping host and output results  ping host 
2 get whois information for domain  whois domain 
3 get DNS information for domain  dig domain 
4 reverse lookup host  dig -x host 
5 download file  wget file 
6 continue a stopped download   wget -c file 







Process Management 



1 display your currently active processes  ps
2 display all running processes  top
3 kill process id pid  kill pid 
4 kill all processes named proc 
killall proc 
5 lists stopped or background jobs; resume a  stopped job in the background bg
6 brings the most recent job to foreground  fg
7 brings job n to the foreground   fg n 







File Permissions  



1 change the permissions of file  to octal, which can be found separately for user,  group, and world by adding:   chmod octal file 

● 4 – read (r) 

● 2 – write (w) 

● 1 – execute (x) 

Examples: chmod 777 – read, write, execute for all 

chmod 755 – rwx for owner, rx for group and world

For more options, see man chmod.  







SSH  



1 connect to host as user ssh user@host 
2 connect to host on port  port as user  ssh -p port user@host 
3 add your key to host for  user to enable a keyed or passwordless login   ssh-copy-id user@host 







Installation 



1 install a package (Debian) Install from source ./configure make make install dpkg -i pkg.deb 
2 install a package (RPM)   rpm -Uvh pkg.rpm 







Shortcuts  



1 halts the current command   Ctrl+C 
2 stops the current command, resume with  fg in the foreground or bg in the background  Ctrl+Z 
3 log out of current session, similar to exit  Ctrl+D 
4 erases one word in the current line  Ctrl+W 
5 erases the whole line   Ctrl+U 
6 type to bring up a recent command !! - repeats the last command Ctrl+R 
7 log out of current session   exit 







Searching  



1 search for pattern in files  grep pattern files 
2 search recursively for  pattern in dir  grep -r pattern dir 
3 search for pattern in the  output of command  command | grep pattern 
4 find all instances of file   locate file 







System Related



1 to change your current password passwd
2 Shuts the system down shutdown
3 Shuts the system down to halt immediately. shutdown -h now
4 Shuts the system down immediately and the system reboots shutdown -r now



 
 
 
 

Comments