Contents...
Linux and UNIX based operating system are very powerful. Although Linux interface is user friendly and easy to understand but there are lots of commands that every Linux user should know it. There are lots of thing you can do with the help of commands but can not using GUI.
In this tutorial I will provide a list of Linux commands that every Linux should know it will be also helpful for any beginner to know. Below commands should work on CentOS, Red Hat, Ubuntu, Linux Mint or any other Linux Operating System.
Suggested Read: Top 25 Linux Find Command Examples
1. To Show Time and Date
# date Tue Feb 7 18:37:39 MSK 2017
2. Checking System Uptime
Check how long system has been running and up?
# uptime 18:39:33 up 583 days, 5:45, 0 users, load average: 0.07, 0.02, 0.00
3. To Know Who Are Logged In As
# whoami root
4. Check History Of Successful Logged In User
# last reboot system boot 2.6.32-042stab08 Sun Jul 5 13:54 - 07:24 (583+18:29) reboot system boot 2.6.32-042stab08 Fri Mar 7 03:21 - 13:53 (485+09:31) reboot system boot 2.6.32-042stab05 Mon Sep 17 22:37 - 13:53 (1020+15:15) reboot system boot 2.6.32-042stab05 Mon Sep 17 20:07 - 22:36 (02:28) reboot system boot 2.6.32-042stab05 Tue Apr 24 20:06 - 20:07 (146+00:00) reboot system boot 2.6.32-042stab05 Thu Apr 12 22:14 - 20:07 (157+21:52) reboot system boot 2.6.18-194.8.1.e Mon Apr 2 10:06 - 22:13 (10+12:06) reboot system boot 2.6.32-042stab03 Tue Feb 21 10:41 - 03:30 (40+15:49) wizap pts/1 c-68-51-136-80.h Sun Nov 20 11:16 - 12:00 (00:43) reboot system boot 2.6.32-042stab03 Mon Nov 7 06:52 - 03:30 (146+19:38) wtmp begins Mon Nov 7 06:52:25 2011
5. Go To Home Directory
# cd
Follow the above command to move to direct home directory just typing cd+enter.
If you want to move to diffrent directory follow the below command
# cd /opt
6. Check Current Working Directory
If you want to know where are you working just type the below command to show the current working Directory
# pwd /home/duser
7. Listing The File And Directory
You can list the all file and directory just typing the below command but it will show the hidden files.
# ls ajenti-repo-1.0-1.noarch.rpm aquota.user boot dev home lib media nohup.out proc root selinux sys usr aquota.group bin cgroup etc index.php lib64 mnt opt reboot sbin srv tmp var
List The File And Directory With Full Detail
Type the below command to know the files and directories with full details.
# ls -l total 236 dr-xr-xr-x 2 root root 4096 Oct 26 12:13 bin dr-xr-xr-x 3 root root 4096 Sep 23 2011 boot drwxr-xr-x 2 root root 4096 Jul 12 2016 cgroup drwxr-xr-x 8 root root 2180 Jun 10 2016 dev drwxr-xr-x 101 root root 12288 Feb 6 09:37 etc drwxr-xr-x 4 root root 4096 Dec 3 2015 home -rw-r--r-- 1 root root 43 Jun 17 2015 index.php dr-xr-xr-x 10 root root 4096 Oct 26 12:13 lib dr-xr-xr-x 10 root root 12288 Oct 26 12:13 lib64 drwxr-xr-x 2 root root 4096 Sep 23 2011 media
To Show The Hidden Files
Type the below command to show the hidden files.
# ls -al total 244 dr-xr-xr-x 22 root root 4096 Oct 26 11:54 . dr-xr-xr-x 22 root root 4096 Oct 26 11:54 .. -rw-r--r-- 1 root root 0 Jul 5 2015 .autofsck -rw-r--r-- 1 root root 0 Jul 5 2015 .autorelabel dr-xr-xr-x 2 root root 4096 Oct 26 12:13 bin dr-xr-xr-x 3 root root 4096 Sep 23 2011 boot drwxr-xr-x 2 root root 4096 Jul 12 2016 cgroup drwxr-xr-x 8 root root 2180 Jun 10 2016 dev drwxr-xr-x 101 root root 12288 Feb 6 09:37 etc drwxr-xr-x 4 root root 4096 Dec 3 2015 home -rw-r--r-- 1 root root 43 Jun 17 2015 index.php dr-xr-xr-x 10 root root 4096 Oct 26 12:13 lib dr-xr-xr-x 10 root root 12288 Oct 26 12:13 lib64 drwxr-xr-x 2 root root 4096 Sep 23 2011 media
8. To Show The Current Active Processes On System
Follow the below command to check the current active processes on system.
# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 136 0.0 0.0 10680 4 ? S<s 2015 0:00 /sbin/udevd -d root 483 0.0 0.1 249860 4620 ? Sl 2015 20:16 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5 root 736 0.0 0.1 139176 3500 ? Ss 2015 29:57 /usr/bin/perl -wT /usr/sbin/munin-node root 967 0.0 0.0 4068 8 tty1 Ss+ 2015 0:00 /sbin/mingetty console root 997 0.0 0.0 4068 8 tty2 Ss+ 2015 0:00 /sbin/mingetty tty2 root 2583 0.0 0.0 106276 8 ? S 2016 0:00 /bin/sh /usr/local/bin/inotifywait.sh /var/www/chroot/ root 2584 0.0 0.0 24204 1584 ? S 2016 0:12 inotifywait -mrq -e CREATE --format %w%f --exclude .*/tmp /var/www/chroot/ root 2585 0.0 0.0 107300 1552 ? S 2016 2:07 /bin/sh /usr/local/bin/inotifywait.sh /var/www/chroot/ root 4859 0.0 0.1 118164 4528 ? Ss 06:39 0:00 sshd: dsharma-dev [priv] 10093 4861 0.0 0.0 118164 2160 ? S 06:39 0:00 sshd: dsharma-dev@notty 10093 4862 0.0 0.0 118164 1736 ? Ss 06:39 0:00 sshd: dsharma-dev@internal-sftp apache 5407 0.0 2.0 746924 56324 ? S 06:45 0:02 /usr/sbin/httpd root 5940 0.0 0.1 118168 4524 ? Ss 06:47 0:00 sshd: dsharma [priv]
9. To Know The All Running Process On System
Follow the below command to see the all running processes on system.
# top top - 07:41:27 up 583 days, 18:46, 0 users, load average: 0.25, 0.14, 0.08 Tasks: 140 total, 1 running, 139 sleeping, 0 stopped, 0 zombie Cpu(s): 0.6%us, 0.1%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.1%st Mem: 2764752k total, 632152k used, 2132600k free, 0k buffers Swap: 5529504k total, 112652k used, 5416852k free, 298884k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 21328 364 248 S 0.0 0.0 1:08.74 init 136 root 16 -4 10680 4 0 S 0.0 0.0 0:00.02 udevd 483 root 20 0 244m 4624 404 S 0.0 0.2 20:16.61 rsyslogd 736 root 20 0 135m 3500 652 S 0.0 0.1 29:57.26 munin-node 967 root 20 0 4068 8 4 S 0.0 0.0 0:00.00 mingetty 997 root 20 0 4068 8 4 S 0.0 0.0 0:00.00 mingetty 2583 root 20 0 103m 8 4 S 0.0 0.0 0:00.00 inotifywait.sh 2584 root 20 0 24204 1584 240 S 0.0 0.1 0:12.96 inotifywait 2585 root 20 0 104m 1552 392 S 0.0 0.1 2:07.12 inotifywait.sh 4859 root 20 0 115m 4528 3428 S 0.0 0.2 0:00.01 sshd 4861 dsharma- 20 0 115m 2160 992 S 0.0 0.1 0:00.72 sshd 4862 dsharma- 20 0 115m 1736 580 S 0.0 0.1 0:00.44 sshd 5940 root 20 0 115m 4524 3428 S 0.0 0.2 0:00.00 sshd 5942 dsharma 20 0 115m 2052 920 S 0.0 0.1 0:00.01 sshd
10. Killing The Process Using Process ID (PID)
Follow the below command to kill the rsyslogd process use the above command to know the its process id.
# kill 483
11. Removing File From System
As system administrator you always need to remove the unwanted file to clean the system. Follow the below command to remove the files
# rm File_Name
Removing File Forcefully With Verbose Mode
# rm -rvf File_Name
Removing Empty Directory
Follow the below command to remove the empty directory.
# rmdir Directory_Name
Remove The Directory With Its Content
# rm -r Directory_name
12. Creating A File
There are multiple command to create a file usring the terminal.
# touch File_Name # echo -n > File_Name # vim File_name # cat > File_Name Than type ctrl+D
13. Creating File With Content
Follow the below command to create file with some content.
# echo This is my test file > File_Name
14. Moving A File
Use below command to move files from one directory to another directory.
# mv File1 File2
15. Show Memory Status
If you want to know about system memory status than follow the below command.
# free -m total used free shared buffers cached Mem: 2699 661 2038 237 0 281 -/+ buffers/cache: 379 2320 Swap: 5399 107 5292
In GB
# free -g total used free shared buffers cached Mem: 2 0 2 0 0 0 -/+ buffers/cache: 0 2 Swap: 5 0 5
16. To Know CPU Information
As a system administrator you always need to know about the the CPU information of new system.
Run the below command to know the CPU Information.
# cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 42 model name : Intel(R) Xeon(R) CPU E31270 @ 3.40GHz stepping : 7 cpu MHz : 3392.227 cache size : 8192 KB physical id : 0 siblings : 8 core id : 0 cpu cores : 4 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid bogomips : 6784.45 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 42 model name : Intel(R) Xeon(R) CPU E31270 @ 3.40GHz stepping : 7 cpu MHz : 3392.227 cache size : 8192 KB physical id : 0 siblings : 8 core id : 1 cpu cores : 4 apicid : 2 initial apicid : 2 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid bogomips : 6784.45 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management:
17. To Know Disk Usage
You can check the disk usage in human readable format using the below command.
# df -h Filesystem Size Used Avail Use% Mounted on /dev/simfs 30G 22G 8.8G 71% / none 1.4G 16K 1.4G 1% /dev tmpfs 512M 52K 512M 1% /var/lib/php/session /dev/sda1 497M 155M 343M 32% /boot
18. To Know The System Information
Type the below command to know the system information like Kernel Name, Host Name, Kernel Release Number, Processor Type etc.
# uname -a Linux client1.example.com 2.6.32-042stab081.5 #1 SMP Mon Sep 30 16:52:24 MSK 2013 x86_64 x86_64 x86_64 GNU/Linux
19. Copy File And Directory
Use cp command to copy file and directory. Follow the below command to copy a file.
# cp fine_name /opt/
Run below command to copy a directory. To copy a directory you will need to use -r option.
# cp Download/ /opt/
20. Create New Directory
Use below command to create empty directory.
# mkdir /directory_name [creating directory under /] # mkdir directory_name [creating directory in current path] # mkdir -p /opt/test/directory_name [creating collaborative directory]
21. Clear Screen
Follow the below command to clear screen.
# clear
22. Search content in file
# grep test ubuntu This is my test file Creating test file Neo working on test file
In above command we are searching for ” test ” string in ubuntu file.
23. Securely Copy File On Remote Host
# scp my_file.txt [email protected]/root/downlaod/
24. To Shutdown System
Follow the below command to power off the system immediately.
# shutdown -h now
25. To Reboot System
Run the below command to reboot the system.
# reboot
I hope this article will be helpful to understand the Basic Linux Commands. Read our another article Easy Steps to Clone Your HDD (Hard Drive) using dd and /etc/hosts vs. /etc/resolv.conf in Linux. If you have any queries and problem please comment in comment section or you can also ask your question.
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment