Learn Basic Linux System Commands For Linux Foundation Certified IT Associate (LFCA) Certification
In this article, we are going to learn Basic Linux System Commands (administration commands) that are required for the LFCA certification exam. Linux system gives a tremendous pool of commands that you can use to administer and manage with your system and they are as per the following.
Follow the below Article for Basic Linux System Commands:
1. uptime Command
The uptime command shows how long your system has been running since the last time it was turned on. With no contentions, it shows a host of information, for example, the time the system has been running, clients users with running sessions, and load average.
$ uptime 11:14:58 up 1:54, 1 user, load average: 0.82, 1.60, 1.56
To get the specific date and time since the system was turned on, utilize the
$ uptime -s 2021-04-11 09:20:02
To get the specific span in a more easy-to-use format affix the
$ uptime -p up 1 hour, 55 minutes
2. uname Command
The uname command prints out essential information in regards to your operating system and hidden equipment. With no contentions, the
uname command just prints out the operating system– which for this situation is Linux.
$ uname Linux
By using uname Linux command you can check the Linux version and also get the below system information’s i.e. :
- Operating System name
- The hostname of the System
- Operating System architecture i.e. 32 Bit or 64 Bit
- Kernel Released & Compiled date & time
To get all the above details you can use the uname command with argument
-a Refer to the command below.
$ uname -a Linux ubuntu 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
To show the kernel release affix the
$ uname -r 5.4.0-65-generic
To get the kernel version utilize the -v flag.
$ uname -v #50~20.04.1-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021
To see the type of kernel you are utilizing, utilize the -s flag.
$ uname -s Linux
For additional commands, check the assistance section as follows.
$ uname --help
3. whoami Command
The whoami command shows the as of now logged-in user as shown below.
$ whoami itsmarttricks
4. w Command
The w command gives information data about right now logged-in users.
$ w 11:24:37 up 2:04, 1 user, load average: 2.04, 1.95, 1.74 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT itsmarttricks tty7 :0 09:21 2:04m 7:52 0.52s xfce4-session
5. free Command
To check Memory usage Information like Total Available Memory, Used Memory, Free Memory, Shared, Buffer and cached Memory, Swap space/Memory Usage Information you can just run the free command. Refer to the command below.
$ free total used free shared buff/cache available Mem: 8041516 2806424 1918232 988216 3316860 3940216 Swap: 11534332 0 11534332
To show information data in a more human-readable format, append the
$ free -h total used free shared buff/cache available Mem: 7.7Gi 2.7Gi 1.9Gi 954Mi 3.2Gi 3.8Gi Swap: 10Gi 0B 10Gi
6. top Command
This is among the valuable tools in a Linux system. The top command gives a brief look at the at present running processes and furthermore gives a continuous outline of the system resource utilization. At the actual top of the yield, you get information about the uptime, running tasks, CPU, and memory use.
7. ps Command
ps command records the at present running process on the current shell close by their PIDs.
$ ps PID TTY TIME CMD 10994 pts/0 00:00:00 bash 12858 pts/0 00:00:00 ps
To display the currently running process of the user, use the -u option as shown.
$ ps -u itsmarttricks
8. sudo Command
A portmanteau for Super User do, sudo is a command-line utility that concedes an ordinary user capacity to perform administrative or raised undertakings. Prior to utilizing the command, guarantee that the user is first added to the sudo group. Once added, start the command with sudo first.
For example, to update the package lists, run the command:
$ sudo apt update
You will be provoked for the password whereupon the errand will be executed.
9. echo Command
The echo command does a lot of things. In the first place, it can print out the estimation of a string on the terminal as appeared.
$ echo “Hey guys. Welcome to Linux” “Hey guys. Welcome to Linux”
You can likewise save a string to a file utilizing the
( > ) redirection operator. On the off chance that the file doesn’t exist, it will be made.
$ echo “Hey guys. Welcome to Linux” > file1.txt $ cat file1.txt “Hey guys. Welcome to Linux”
Please note that this overwrites a file. To add or add data utilize the twofold more noteworthy than operator
( >> ).
$ echo “We hope you will enjoy the ride” >> file1.txt $ cat file1.txt “Hey guys. Welcome to Linux” We hope you will enjoy the ride
Also, an echo command can be utilized to show environmental factors. For instance, to show the as of now signed in user run:
$ echo $USER itsmarttricks
To show the path to the home directory run:
$ echo $HOME /home/itsmarttricks
10. history Command
As the name recommends, the history command gives you a history of the commands that were last executed on the terminal.
11. head Command
In some cases, you should have a look at the initial not many lines of a text file as opposed to survey the whole record. A head command is a command-line apparatus that shows the initial not many lines in a file. As a matter of course, it showed the initial 10 lines.
$ head /etc/ssh/ssh_config
You can pass the
-n flag to specify the number of lines to be displayed. For example, to display 5 lines run the command as follows:
$ head -n 5 /etc/ssh/ssh_config
12. tail Command
The tail command is the specific inverse of the head command. It shows the last 10 lines of a file.
$ tail /etc/ssh/ssh_config
Just like the head command, you can define the number of lines to be displayed. For example, to view the last 5 lines of a file, run:
$ tail -n 5 /etc/ssh/ssh_config
13. wget Command
The wget command is a command-line tool utilized for downloading files over the web. It upholds various functionalities including downloading numerous files, restricting download data transmission, downloading behind the scenes thus considerably more.
In its fundamental structure, it downloads a file from a given URL. In the order underneath, we are downloading the most latest Linux kernel.
$ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.11.4.tar.xz
To save a file to a different directory, use the -P flag followed by the path to the directory followed by the URL. For example, to download a file to the /opt directory, run the command.
$ wget -P /opt https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.11.4.tar.xz
To download and save a file under a different name, use the -O flag followed by the desired file name.
$ wget -O latest.tar.xz https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.11.4.tar.xz
14. finger Command
The finger command gives some concise data about the login client including the name, shell, home index, and the time since the user has signed in.
$ finger itsmarttricks Login: itsmarttricks Name: itsmarttricks Directory: /home/itsmarttricks Shell: /bin/bash On since Wed Mar 17 09:21 (IST) on tty7 from :0 2 hours 52 minutes idle No mail. No Plan.
15. alias Command
The alias command allows you to assign your own name to a Linux command for purposes of convenience. For example to assign an alias called
show to the command
ls -a, run the alias command as shown.
$ alias show=ls -a $ show
16. passwd Command
The passwd command allows you to change your password. Essentially run the passwd command as appeared.
You will be prompted for your current password, whereupon you will give a new password and later confirm it.
Moreover, you can change the password for another user just by passing the username of the user as a contention.
$ passwd username
17. groups Command
To check which groups a user has a place with run the groups command as follows:
$ groups OR $ groups itsmarttricks itsmarttricks sudo
18. du Command
du command is a powerful command in Linux and Unix Operating System used to check disk usage of files or directories. Need to watch out for the disk utilization of your files and folders? The du command – short for diskuse – is the standard command for checking disk use of files and directories.
The command follows a basic syntax as shown.
$ du OPTIONS FILE
For example, to see the disk use in an intelligible in your current directory, execute the command:
$ du -h .
To check the disk usage in another directory, for example /var/log/ run the command:
$ du -h /var/log
19. df Command
df command (also referred to as Disk Free) is a Linux and Unix operating system related command used to check Disk Space/Disk Usage. not only disk space df command is useful for more than that.
The df command – short for disk free – checks the total disk space, space being utilized, and the available disk space in different file systems. It takes the syntax shown below:
$ df OPTIONS FILE
The most crucial options are –
-T flag prints the file system type whilst the
-h flag displays the output in a human-readable format.
The command below lists the free disk space in all the filesystems.
$ df -Th
20. chown Command
The chown command is utilized for changing the user and group ownership of files and directories. When you list the substance of a directory using the ls -l command, you will get an output similar to what we have here.
$ ls -l
In columns 3 and 4, you can clearly see the username. This refers to the user’s first point and the second entry group, which is also the username. When a new user is created, they are assigned a new default group, of which they are only members by default. This indicates that the files or directories have not been shared with anyone.
Using the chown command, you can change file ownership very easily. Just give the name of the whole owner and then the name of the group separated by the whole colon (:), this is an advanced function and you will have to invoke the sudo command.
For example, to change the group of the file1.txt to james but retain the owner as itsmarttricks run.
$ sudo chown itsmarttricks:james file1.txt $ ls -l
To change both the owner as well as the group, run the command:
$ sudo chown james:james file1.txt $ ls -l
To change ownership of a directory use the -R flag for recursive. We have created a new directory called data and we shall change both the user and group to james.
$ sudo chown -R james:james data $ ls -l
21. chmod Command
chmod command is used in Linux-related operating systems to Change file mode bits. In simple language, you can change the permissions of files and directories in Linux using chmod command. There are two methods by which we can change the permissions:
The chmod command is utilized to set or modify file or folder permissions. Back to the output of the ls – l order. The primary segment contains the accompanying characters
The first character ( d ) demonstrates that this is a directory. A file is addressed utilizing a hyphen ( – ). The remainder of the nine characters are separated into 3 arrangements of rwx (read, write, execute) flags. The initially set represents the record owner (u), the second represents the group (g), and the last set represents any remaining users.
There are two different ways of assigning file permissions: Numeric and symbolic (text) notation. For Numeric notation, every one of the flags represents a worth as appeared.
r = 4 w = 2 x = 1 No permissions = 0
To get the file permissions of a file simply add the corresponding values in all the sets. For example:
- For the owner for the file (u) rwx = 4+2+1 = 7
- For the group (g) rwx = 4+2+1 = 7
- For other (o) r-x = 4+0+1 = 5
Finally, we arrive at the notation 775.
Let’s take another example of file 1.txt.
-rw-rw-r-- 1 james james 59 Mar 6 18:03 file1.txt
Here, we have rw-rw-r–.
Let’s add them up.
- For the owner for the file (u) rw- = 4+2+0 = 6
- For the group (g) rw- = 4+2+0 = 6
- For other (o) r– = 4+0+0 = 4
This comes to 644.
We will set this to 775. This gives the owner and group of the file all permissions – i.e rwx, and other users read and execute permissions only.
Run the command:
$ sudo chmod 775 file1.txt
The other way of assigning permissions is using symbolic notation. Using the symbolic notation, the following flags are used to either add or remove permissions
-– Removes the permissions.
+– Adds specified permissions.
=– Sets the current permissions to the specified permissions. If there are no permissions specified after the = symbol, then all permissions from the specified user class are removed.
For example, to remove execute permissions from all sets – owner of the file, group members, and other users, run the command.
$ sudo chmod a-x file1.txt
To assign group members read permissions only and not write and execute, run.
$ sudo chmod g=r file1.txt
To remove write permissions from other users, run.
$ sudo chmod o-r file1.txt
To give the group members and other users read and write permissions, run:
$ sudo chmod og+rw file1.txt
To assign permissions to directories, use the
-R flag for setting permissions recursively.
$ sudo chmod -R 755 /var/www/html
22. The poweroff / reboot Commands
The poweroff command, as the name suggests, shuts down your system.
Another command that achieves a similar undertaking is the shutdown command as appeared.
$ shutdown -h now
-h flag stands for a halt, implying stopping the system. The second parameter is the time option which can also be specified in minutes and hours.
The command below displays a message to all logged-in users notifying them of the system shutdown that’s scheduled in 5 minutes.
$ shutdown -h +5 “System is shutting down shortly. Please save your work.”
To reboot the system, use the reboot command as shown.
Alternatively, you can reboot using the shutdown command with an
-r option as shown.
$ shutdown -r now
23. exit Command
The exit command closes the terminal or exits the shell. If you have initiated an SSH session, the session is closed.
24. man Command
The man command, short for manual, shows the manual pages for any Linux command. It proves to be useful when you need to perceive how a command is utilized. It gives a detailed description of the command including a concise summary, choices, returns statuses with, authors to specify a couple.
For example, to view insights on the ls command, run:
$ man ls
That’s all, In this article, we have explained Learn Basic Linux System Commands For LFCA Certification Exam. I hope you enjoy this article. If you like this article, then just share it and then do subscribe to email alerts for Linux, Windows, macOS, Android, Internet, Firewall and Security, CCTV tutorials. If you have any questions or doubts about this article, please comment.