The current world is running on computers. Knowing simple Unix commands or basic Unix commands enables you to dive into the world of Unix or Linux system. It also allows confirming the current system state and control files or directories. Here is the list of Unix command line basics for beginners.
Once the Unix startup is concluded, it will display a login window for the user to insert a username and password. If the username and password are valid, then the Unix system will begin a login session. After this, the user can initiate a screen that operates a shell application.
Here’s an extensive Unix commands list you should know:
The cal command is one of the most important Unix commands. This command is used to display the calendar of the entered value. By default, cal command displays the current month calendar as a result. cal is a conventional and one of the most basic of all the Unix commands. It displays an ASCII calendar of the assigned month or year.
Example: The following command will display the calendar for July 2019.
The banner command is one of the common Unix commands. This command displays a large ASCII description variant of the text that is given to it as its application arguments. In other words, this command displays a large banner on the conventional output window.
Syntax: banner message
Example: Print “Hello World” as the banner
If you want to learn Unix commands then you must know all the basic commands first. The whoami command is an important part of the UNIX command line tutorial. This command displays the username/userid of the currently logged-in user. This command is found in many Unix-like operating systems. It is also available in the Windows operating system.
Syntax: whoami [option]
Example: Diaply currently logged-in user
The ls the Unix command to list directories. If you want to view the list of files on the computer system then the ‘ls’ command is used. This is one of the most important Unix commands. It displays the files /directories present in the current directory. It also supports many options. For example, if you want to display hidden files then ls command is used with the -a parameter.
$ ls -a
The cat is the Unix command to create a directory. In other words, the ‘cat’ command is applied to present text files. The great thing about this command is that it can also be utilized for copying, merging, and creating new files. The cat is also known as a concatenating command. It is one of the most regularly used commands in Unix. It is one all singing all dancing command because it allows us to create single or many files, view check files, concatenate and redirect results in terminal or files.
Example: The following command is creating a new file test1 by using the cat command.
In UNIX, rm is a primary command used to remove things such as files, lists, and typical links from file systems and also specific files such as machine nodes, channels, and devices, just like the del command in MS-DOS. This command is one of the most important commands of the UNIX commands cheat sheet.
Syntax: rm filename
Example: rm test1
The above example is displaying the removal of the file named test1. rm eliminates each defined file. By default, it does not eliminate lists. If the -I or — the interactive=once alternative is provided, and the options -r, -R, or –recursive is mentioned, then rm hints to the user for whether to continue with the whole process.
The cp command is the Unix command to copy the directory. This is one of the most used UNIX commands. It copies any text file to the directory. The only condition is that files should not exist already in the directory or are more latest than the files currently present in the directory. The alternative “-‐u” indicates “update,”
Syntax: cp filename.txt
Pico is a part of a Pine command. This is one of the advanced Unix commands. This command begins an uncomplicated but powerful textbase mail application. Pine enables you to obtain, create, transmit, and secure e-mail communications, communicating with anyone who is connected to the World Wide Web.
Syntax: pico -w nameoffile
To produce a file named "test" with pico type:
Example: pico -w test
Messages written in Pine are published utilizing a file editor application named “pico”.The pico can also be applied from the UNIX to build and publish other files. By default, pico splits long lines between words, which provides a more normal display in most mail-reading applications.
The finger command is one important command of the Unix commands cheat sheet. It is utilized to show details about users on UNIX systems. Finger reveals a particular user’s complete name, last login, and when the user saw their mail. If you wanted to obtain details about a particular user, you would enter finger user_name. If you wanted to find a particular user on the Internet, just type finger username@host. You can also improve the performance of the finger by adding choices to the finger command. For example, if you have someone’s full user ID, then enter finger -m username, which is much faster than the regular finger command.
finger [-mlsqibfwhp] [username]
Lynx is actually a web browser available on the Unix system. Lynx is a text-only browser interface and it is one of the advanced Unix commands. Lynx can be very helpful if the user wants quick access to valuable information, or wants to use a text-based terminal.
To initialize Lynx user has to just type lynx in any Unix session. By default, Lynx will begin showing the information. If you want to have lynx browse a particular page once it begins, then just type:
Syntax: lynx URL
If you want to learn Unix commands then the man command is one of the important Unix commands. The man command will show the manual pages for most UNIX commands. If you want more information on any of the Unix commands then you can use the man command to see if there is an online page available. For instance, if you need assistance on the move (mv) command, you would enter:
The Unix pmap command shows the process of memory usage or various processes. Pmap displays information about the memory usage map or the address space. Memory is the most important component of the operating system and pmap is the most important Unix command. You just have to mention the process id in order to find out the memory usage of the processes. In the result, it shows full address, kbytes, mode, and mapping.
Syntax: pmap options
Touch command is a command-line tool that is applied to update timestamps on files. UNIX operating system stores timestamp data of each file or directory including access time, update time, and change time. It can be used to alter timestamps by using the touch command either to update timestamps to the latest time or to alter it to a date in the past.
Syntax: touch -a filename
Example: touch -a test11
The grep is one of the most advanced Unix commands. This command is used to search for a given string in a specific file. For example, if you have a file test11.txt. It contains an article of 1000 words. Now, if you want to search a particular text from this file then the grep command can be used.
Syntax: grep -i filename
Example: grep -i “Jeff” test11.text
The above command will search for the string Jeff in the file test11.txt. Grep is a command-line tool for finding plain-text data that match a regular expression. In other words, this command filter searches a specific file for a specific pattern of characters.
The shutdown command is an administrator-level command. This command as the name suggests is used to shut down the system and turn the power off instantly. If you want to shut down your system immediately then you can use the now option and if you want to shut down your system after 15 min then it can be done by adding +15 min as an extension.
shutdown -h now
The above command is used to shut down the system immediately. Now, if you want to reboot it then it can be done by using -r option.
Example: Shutdown after 15 min
shutdown -h +15
Example of rebooting the system
shutdown -r now
This command is used to create a new user for the operating system. For instance, you could easily use the following command to establish a new user account with the username “john” and a default home directory:
The user account that is being created can be customized further by specifying additional settings.
You can add the following attributes in front of useradd:
c: Add a remark, such as a user’s full name or a description, to their account.
d: Establishes the user’s home directory.
g: Change the user’s default group.
G: Set the supplemental groups for the user.
m: Create a home directory if the user’s home directory doesn’t already exist.
s: Establish the user’s default shell.
You could use the following command to establish a user account for “john” with the full name “John Doe” and the home directory “/home/john”:
useradd -c "John Doe" -d /home/john john
uniq is a Unix command that is used to remove duplicate lines from a file or stream of text. It analyzes the lines next to each other and eliminates duplicate lines, leaving only one instance of each distinct line.
To remove duplicate lines from a file called start.txt and write the output to a new file called end.txt, you could use the following command:
uniq start.txt > end.txt
As the name implies, the command sorts the lines in a file alphabetically or numerically. The command can arrange the lines numerically, alphabetically, or according to particular fields contained within each line.
Here are some options to use with the sort command:
n: Sort the lines numerically, rather than alphabetically.
r: Reverse the sort order.
t: Use a specific character as the field delimiter when sorting.
k: Specify which field to sort on (for example, -k 2 would sort on the second field).
Imagine that we have a file called employees.txt that contains the following data:
John Smith, 30, Manager Jane Doe, 25, Developer
To sort the employees by age in ascending order, we could use the sort command with the -n and -k options like so,
sort -n -k 2 employees.txt
Then, the output will look like this:
Jane Doe, 25, Developer John Smith, 30, Manager
Count the number of lines, words, or characters in a file using the ‘wc’ command.
Here are some common options for wc:
l: Count the number of lines in the input.
w: Count the number of words in the input.
c: Count the number of characters in the input.
Using our previous employees.txt file, we can use this command to count the lines.
wc -l employees.txt
The output will look something like this:
Linux is full of files with tons of lines. Use the head command to display the first few lines of a file.
You can apply the following typical characteristics to the head command:
n: Indicate how many lines to display. For instance, the -n 10 option would show the input’s first 10 lines.
q: Quiet mode; the file name is not displayed before the output.
c: Indicate how many characters to display.
To display the first 1 line of a file, you could use the following command:
head -n 1 employees.txt
John Smith, 30, Manager
Learn to code with our Free Courses for everyone!