1. ls list all the contents of a directory (Display One File Per Line Using ls -1 | Display File Size in Human Readable Format Using ls -lh | Display Hidden Files Using ls -a (or) ls -A | )
2. ll list all the contents of a directory with its permissions, size etc
3. cd / cd .. move in an out of directories
4. mv / cp: Copy file1 to file2 preserving the mode, ownership and timestamp.
$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -i file1 file2
mv command examples
Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ mv -i file1 file2
Note: mv -f is just the opposite, which will overwrite file2 without prompting.
mv -v will print what is happening during file rename, which is useful in some cases.
$ mv -v file1 file2
5. man to find documentation about a command
6. mkdir: to make a directory
mkdir command examples Following example creates a directory called temp under your home directory.
$ mkdir ~/temp
Create nested directories using one mkdir command. If any of these directories exist already, it will not display any error. If any of these directories doesn’t exist, it will create them.
$ mkdir -p dir1/dir2/dir3/dir4/
7. rmdir to delete a directory
8. touch to create an empty file
9.rm to remove a file
10. clear (same as cls in winows) clear the clutter from terminal window
11. rm -rf / << the command that we should never use. it will clean the whole system.
12.TAR: Create a new tar archive.
$ tar cvf archive_name.tar dirname/
Extract from an existing tar archive.
$ tar xvf archive_name.tar
View an existing tar archive.
$ tar tvf archive_name.tar
13. grep : to extract data. check example.
nesi@Alpha:~$ ip route default via 192.168.1.1 dev enp7s0 proto static metric 100 default via 192.168.75.3 dev wlp6s0 proto static metric 600 192.168.1.0/24 dev enp7s0 proto kernel scope link src 192.168.1.95 metric 100 192.168.75.0/24 dev wlp6s0 proto kernel scope link src 192.168.75.94 metric 600 192.168.250.0/24 dev anbox0 proto kernel scope link src 192.168.250.1 nesi@Alpha:~$ ip route | grep default default via 192.168.1.1 dev enp7s0 proto static metric 100 default via 192.168.75.3 dev wlp6s0 proto static metric 600
14. sudo / su:
su command examples : Switch to a different user account using su command. Super user can switch to any other user without entering their password. some linux distributions nowadays only allow sudo.
$ su - USERNAME
Execute a single command from a different account name. In the following example, john can execute the ls command as raj username. Once the command is executed, it will come back to john’s account.
[john@dev-server]$ su - raj -c 'ls' [john@dev-server]$
Sudo: is same like “run as administrator” in windows
15. pwd (print working directory) show us the current directory in which the terminal is running on.
16. ps show currently running processes
17. passwd command : Change your password from command line using passwd. This will prompt for the old password followed by the new password.
Super user can use passwd command to reset others password. This will not prompt for current password of the user.
# passwd USERNAME
Remove password for a specific user. Root user can disable password for a specific user. Once the password is disabled, the user can login without entering the password.
# passwd -d USERNAME
18. ifconfig command : Use ifconfig command to view or configure a network interface on the Linux system.View all the interfaces along with status.
$ ifconfig -a
Start or stop a specific interface using up and down command as shown below.
$ ifconfig eth0 up $ ifconfig eth0 down
set IP and SM :
$ ifconfig eth0 192.168.50.5 netmask 255.255.255.0
19. uname command : Uname command displays important information about the system such as — Kernel name, Host name, Kernel release number,
Processor type, etc.,Sample uname output from a Ubuntu laptop is shown below.
$ uname -a Linux Alpha 4.10.0-35-generic #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
20. whatis command : Whatis command displays a single line description about a command.
$ whatis ls ls (1) - list directory contents $ whatis ifconfig ifconfig (8) - configure a network interface
21. whereis command : When you want to find out where a specific Unix command exists (for example, where does ls command exists?), you can execute the following command.
$ whereis ls ls: /bin/ls /usr/share/man/man1/ls.1.gz
22. locate command : Using locate command you can quickly search for the location of a specific file (or group of files). Locate command uses the database created by updatedb. The example below shows all files in the system that contains the word crontab in it.
$ locate crontab /etc/anacrontab /etc/crontab /usr/bin/crontab /usr/share/doc/cron/examples/crontab2english.pl.gz /usr/share/man/man1/crontab.1.gz
23. tail command : read a text file on terminal.
usage examples: Print the last 10 lines of a file by default.
$ tail filename.txt
Print N number of lines from the file named filename.txt N refers to the number of lines you want to print
$ tail -n N filename.txt
View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C.
$ tail -f log-file
24. less command : less is very efficient while viewing huge log files, as it doesn’t need to load the full file while opening.
$ less huge-log-file.log
One you open a file using less command, following two keys are very helpful.
CTRL+F – forward one window CTRL+B – backward one window
25. Kill Command – Kill the process by specifying its PID: to kill conventions by sending the TERM signal to the specified process. For the signals, either the signal name or signal number can be used. You need to lookup the pid (process ID) for the process and give it as an argument to kill. Use PS or Top to find pid
nesi@Alpha:~$ ps PID TTY TIME CMD 11671 pts/1 00:00:00 bash 12194 pts/1 00:00:00 ps nesi@Alpha:~$ top 9658 nesi 20 0 1790380 367880 32344 S 12.5 9.3 1:00.76 chromium-b+ 3604 nesi 9 -11 592688 6124 4160 S 6.2 0.2 3:39.36 pulseaudio 12212 nesi 20 0 59776 3524 2948 R 6.2 0.1 0:00.01 top 1 root 20 0 185312 2104 840 S 0.0 0.1 0:01.52 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 4 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:+ 6 root 20 0 0 0 0 S 0.0 0.0 0:00.15 ksoftirqd/0 nesi@Alpha:~$ kill 9658
in this case the kill command will kill the chromium app
26. Xkill Command – kill a client by X resource: xkill is the simplest way to kill a malfunctioning program. When you want to kill a process, initiate xkill which will offer an cross-hair cursor. Click on the window with left cursor which will kill that process. command: xkill
27. top shows information about the top processes in the system (sorted by CPU usage by default): top may not be installed by default. Htop is another app that gives a more detailed approach to this purpose.
28. alias : to assign an alias for a command. for example, to update our package repositories we need to run “ sudo apt-get update” which is a long command. using alias we can make it shorter like may be “update” see the another example below:
we often ping to google to check if our internet is working.
nesi@Alpha:~$ ping 22.214.171.124 PING 126.96.36.199 (188.8.131.52) 56(84) bytes of data. 64 bytes from 184.108.40.206: icmp_seq=1 ttl=58 time=87.8 ms 64 bytes from 220.127.116.11: icmp_seq=2 ttl=58 time=86.4 ms 64 bytes from 18.104.22.168: icmp_seq=3 ttl=58 time=86.6 ms 64 bytes from 22.214.171.124: icmp_seq=4 ttl=58 time=87.2 ms nesi@Alpha:~$ alias g='ping 126.96.36.199' nesi@Alpha:~$ g PING 188.8.131.52 (184.108.40.206) 56(84) bytes of data. 64 bytes from 220.127.116.11: icmp_seq=1 ttl=58 time=87.5 ms 64 bytes from 18.104.22.168: icmp_seq=2 ttl=58 time=86.5 ms 64 bytes from 22.214.171.124: icmp_seq=3 ttl=58 time=86.7 ms
29. apt / apt-get | install, update, dist-upgrade, remove etc : APT-GET How to
30. hostname : display the host name of the system (in case if you want to change the hostname of your laptop, you have to do it inside /etc/hosts file. open it up in gedit or any other text editor and change it. Ex: “sudo gedit /etc/hosts” )
31. uptime – Reports how long the system has been running since last boot. Extremely useful for servers.
32. lsb_release -a or –all: Displays some relevan all of the above information. For instance, if you are running Arch Linux, this will display
LSB Version: 1.4 (lsb_release is part of a software package called the LSB core, which is not necessarily installed on your system by default. to install on ubuntu: sudo apt-get update && sudo apt-get install lsb-core | on CentOS :sudo yum update && sudo yum install redhat-lsb-core)
Distributor ID: Arch
Description: Arch Linux
33. who : shows the list of currently logged in users.
34. shutdown: shuts down your computer. You can use
shutdown -r to restart your computer. (you may have to run it as root, sudo /su)