Linux Shell Commands
S.No. Command Description Example
1 ls List files and directories ls -l (detailed list)
2 cd Change directory cd /home/user
3 pwd Print current working directory pwd
4 mkdir Create a new directory mkdir new_folder
5 rmdir Remove an empty directory rmdir old_folder
6 rm Remove files or directories rm file.txt, rm -r folder
7 cp Copy files or directories cp file1.txt file2.txt
8 mv Move or rename files mv oldname.txt newname.txt
9 touch Create an empty file touch newfile.txt
10 cat Display file content cat file.txt
11 echo Print text to the terminal echo "Hello World"
12 grep Search for a pattern in a file grep "error" logfile.txt
13 find Search for files in a directory find /home -name "file.txt"
14 chmod Change file permissions chmod 755 script.sh
15 chown Change file owner chown user:group file.txt
16 ps Display active processes ps aux
17 top Show real-time system stats top
18 kill Terminate a process kill 1234 (PID)
19 df Display disk space usage df -h
20 du Show directory size du -sh folder
21 tar Archive files tar -cvf archive.tar folder/
22 zip / unzip Compress and extract files zip file.zip file.txt / unzip file.zip
23 wget Download files from the internet wget http://example.com/file.zip
24 curl Transfer data from URLs curl -O http://example.com/file.zip
25 ping Check network connectivity ping google.com
26 ssh Secure remote login ssh
[email protected] 27 scp Securely copy files between systems scp file.txt user@server:/path/
28 man Display manual pages for commands man ls
29 history Show command history `history
30 alias Create a shortcut for a command alias ll='ls -la'
31 df Check available disk space df -h
32 free Show memory usage free -m
33 uname Display system information uname -a
34 uptime Show system uptime uptime
35 whoami Display current user whoami
36 passwd Change user password passwd
37 export Set environment variables export PATH=$PATH:/new/path
38 source Execute a script in the current shell source script.sh
39 #!/bin/bash Shebang line to specify the shell #!/bin/bash (at the start of a script)
40 echo Print text to the terminal echo "Hello World"
41 read Read user input read name; echo "Hello $name"
42 var=value Define a variable name="John"
43 $var Access variable value echo $name
Make a variable available to child
44 export processes export PATH=$PATH:/new/path
if [ $x -gt 10 ]; then echo "Greater"; else
45 if / else Conditional statement
echo "Smaller";
case $var fi echo "1";; "two")
in "one")
46 case Multi-condition checking
echo "2";; esac
47 for loop Loop through items for i in 1 2 3; do echo $i; done
while [ $x -lt 5 ]; do echo $x; x=$((x+1));
48 while loop Execute while condition is true
done
until [ $x -ge 5 ]; do echo $x; x=$((x+1));
49 until loop Execute until condition is true
done
50 break Exit a loop break (inside a loop)
51 continue Skip current iteration of a loop continue (inside a loop)
52 function Define a function my_func() { echo "Hello"; }
53 my_func Call a function my_func
54 exit Exit script execution exit 0
55 && Run command if previous succeeds mkdir test && cd test
56 > Redirect output to a file echo "Hello" > file.txt
57 >> Append output to a file echo "New line" >> file.txt
58 < Take input from a file wc -l < file.txt
59 ` ` Pipe output to another command
60 $(command) Command substitution today=$(date)
61 `command` Alternative command substitution today=`date`
62 $? Get exit status of last command ls /not_exist; echo $?
63 trap Catch signals and execute commands trap "echo 'Signal received'" SIGINT
64 set Enable script debugging options set -x (debug mode)
65 unset Remove a variable unset name
66 test Evaluate expressions test -f file.txt && echo "Exists"