One of the features of the Linux operating system is the Linux command. You can perform all jobs, both simple and complex, by running commands. The Linux terminal is used to carry out the commands. Like the command prompt in Windows OS, the terminal is a command-line interface for interacting with the system. Linux commands have case sensitivities.
Linux provides a powerful command-line interface compared to other operating systems such as Windows and MacOS. Through its terminal, we are able to perform both basic and complicated tasks. We are able to do several fundamental operations, including adding, removing, and moving files. Furthermore, we are capable of handling complex jobs like networking (establishing SSH connections), security, administrative (installing packages, managing users), and many more.
To perform and try these commands on Windows, download mobaxterm.
Linux Directory Commands
1. pwd Command
The current working directory location can be seen by using the pwd command.
Output :
2.mkdir Command
To make a new directory under any directory, use the mkdir command.
3.ls Command
The ls command displays a list of the contents of a directory.
Output :
4.cd Command
To change your current directory, use the cd command and to get one directory back use command as
cd ..
5.touch Command
The touch command is used to generate empty files. We can create numerous empty files by running it once.
Output :
6.vi Command
vi command is used to edit the file or to write the content inside the file.
- To insert or modify in the vi editor, hit i.
- To save your changes, hit esc and then : wq! + enter.
- If you have made changes and do not wish to save them, press esc and then :q! + enter to restore the previous file to its original state.
- To clear the entire content of the file, use esc and then :%d + Enter.
7.cat Command
In the Linux operating system, the cat command has multiple purposes. It can be used to create a file, display its contents, copy its content to another file, and so on.
Output :
8.mv Command
The mv command moves a file or directory from one location to another.
mv current_file_location expected_file_location
Output :
9.cp Command
The cp command copies a file or directory.
cp current_file_location expected_file_location
Output :
10.rm Command
The rm command is used to remove a file.
Output :
11.echo command
The echo command in Linux is a built-in command that displays lines of text or strings supplied as arguments. It is frequently used in shell scripts and batch files to output status information to the screen or a file.
The “>>” operator appends to a current file or creates a new file if the specified file name does not exist in the directory.
12.head command
The head command displays the contents of a file. It displays the first ten lines of a file.
Output :
13.tail command
Tail commands are analogous to head commands. The only difference between the two commands is that the latter displays the final ten lines of the file’s content. It’s useful for reading error messages.
Output :
14.wc Command
The wc command counts the lines, words, and characters in a file.
Output :
15.date Command
The date command displays the current date, time, and time zone, among other information.
Output :
16.cal Command
The cal command is used to display the current month’s calendar with the current date highlighted.
Output :
17.tac Command
The tac command is the opposite of the cat command, as the name implies. It displays the file contents in reverse order.
Output :
18.more command
The more command is quite similar to the cat command in that it displays file content in the same way. The only difference between the two commands is that, for larger files, the more command displays screenful output at a time.
To scroll the page with the more command, use the following keys:
Use the ENTER key to scroll down page by line.
To move to the next page, use the space bar.
b: To return to the previous page.
/ key: Search the string.
Output :
19.less Command
The less command functions similarly to the more command. It also has some additional characteristics, such as “adjustment in width and height of terminal.” In comparison, the more command reduces the output to fit within the terminal’s width.
less file_name
20.rmdir Command
The rmdir command deletes a directory.
rmdir directoy_name
Output :
21.cut Command
The cut command selects a specific column in a file. The ‘-d’ option specifies a delimiter, which can be a space (‘ ‘), a slash (/), a hyphen (-), or anything else. Additionally, the ‘-f’ option is used to define a column number.
cut -d{delimiter} -f{columnNumber} file_name
Output :
22.grep command
Grep is the most powerful and commonly used filter in a Linux system. The ‘grep’ command stands for “global regular expression print.” It is useful for searching the contents of a file. In general, it is utilized with pipes.
Output :
23.sed Command
The sed command is also referred to as stream editor. It is used to alter files based on a regular expression. It does not permanently edit files; rather, the edited material is just displayed. The file itself is unaffected.
Output :
24.tr Command
The tr command is used to convert file text, such as from lower to uppercase.
Output :
25. sort Command
The sort command is used to sort files in alphabetical order.
26.uniq Command
The uniq command is used to generate a sorted list in which each word appears only once.
Output :
27.gzip Command
The gzip command is used to truncate file sizes. It’s a compression tool. It replaces the original file with a compressed file with the ‘.gz’ extension.
gzip fileName1 fileName2 fileName3
28.gunzip Command
The gunzip command decompresses a file. It is the reverse of the gzip command.
gunzip fileName1 fileName2 fileName3
Output :
29.zcat Command
The zcat command is used to view the content of compressed files.
Output :
30.find Command
The find command is used to find a specific file in a directory. It also provides a variety of file search options, including by name, type, and date.
The symbols used after the find command are as follows:
(.): The current directory name.
(/): For root.
Output :
To know about C++ Array : Click here.