What are the linux commands and their functions?

Server Administration ForumWhat are the linux commands and their functions?
Anaa_Eme asked 2 months ago PPU : 5

I was given a project to write about the commands in Linux. I asked google and although I saw a lot of commands but the authors of those websites seem to only confuse me with their explanation of the functions.

Please, I need someone to break down the Linux commands in a a way that i can understand them. Thanks in advance.

uaua




1 Answers
DiamakaCake answered 2 months ago

What are the Linux commands and their functions?

The Linux operating system is an easy-to-use O.S, but for some reason, people tend to think it to be too complicated thereby deferring to its counterpart – the windows operating system. Its ease of use is explicitly seen in its provision of a simple user interface (also called shell, console, terminal, etc). This simple user interface helps to simplify its commands and shortcuts including its basic and complex functionalities.

In Linux, commands are carried out in a shell. Linux shells can be categorized into two; the Bourne shell and the C shell.

The Bourne shell is the most popularly used and has the $ sign as its default prompt. This is the shell that I will use to explain the Linux commands to you in this article. On the other hand, is the C shell command. And it has the % sign as its default sign.

Meanwhile, these two major Linux shells have subcategories. The Bourne shell can be subcategorized into the Korn shell (ksh), Bourne Again Shell (bash), Bourne Shell (sh) among others. The C shell is subcategorized into two: C Shell (csh), TOPS C Shell (tcsh).

Now that the basics of Linux and its shell have been explained, let’s dive into its commands.

It might interest you to know that there are more than 30 commands in Linux and more shortcuts. Nonetheless, you aren’t expected to know all these commands by heart. In fact, knowing how numerous their commands are, the owners of the Linux Os created a command whose sole purpose is to list and explain all the other available commands with their respective examples. This all-purpose command is the man command, and that is what we’re going to start with.

LINUX COMMANDS

man command: like I said earlier, the function of the man command is to teach Linux users how to use all other commands. It shows all the possible options for each command and examples of how those options can be used.

Also, it shows the syntax of all the other Linux commands. In addition to this, it displays all the possible exit status for each command, the authors of these commands, including all the possible errors that a user can encounter while using each command.

Syntax

man [option] [commandName]

Options

—- man [commandName]: this will display all information about the specified command.

—- man [sectionNumber] [commandName]: this option will display only a specific section of the desired command. You can use “man –f [commandName]” to find out a command’s section number.

chmod command: this command is used to change the permissions of a file. Since Linux is a multi-user operating system, it allows its users (especially the root user) to control how the other users can use a particular file.

These permissions can be categorized into three; read, write, and execute. Therefore, the chmod command is the command that a root user can use to modify a file’s permission.

In addition to this, the chmod command is also used to add the Set User ID (setuid), Set User Group ID (setgid), and the sticky bit flags to a file. This particular functionality can only be used if you are using the chmod command syntax that goes with numbers.

Because the Linux operating system has only three modes, when the chmod command syntax that goes with numbers is used, it appears with only three numbers. However, if you use the chmod command to set the above-mentioned flags, the number in the command’s syntax will increase from 3 to 4. Below is the number representation of the setuid, setgid, and the sticky bit flag.

Setuid = 4

Setgid = 2

Sticky bit = 1

Syntax.

The chmod command can be written in two ways.

THE FIRST chmod COMMAND SYNTAX

chmod [REFERENCE] = [PERMISSION] [OPERATOR] FILENAME

The REFERENCE in this syntax simply means the class that the user whose permission is to be modified belongs to. In the Linux operating system, a reference or user’s class is divided into four, and they include:

—- u: this refers to the owner or the root user of the file.

—-g: this refers to all users that are included in the file’s group.

—- o: this refers to users that are neither in the file’s group nor the owner of the file.

—- a or ugo: this refers to all users.

The OPERATORS in the chmod command’s syntax show how those permissions should be applied. This is to say that those operators point to where and how those permissions or modes should be changed. These operators are divided into three, and they include:

—- +: is used to add a mode to a class of users.

—- – (the minus sign): is used to remove a mode from a class of users

—- =: is used to compare and make sure that all the modes are the same to a particular class of users.

The PERMISSION in the chmod command’s syntax means the three modes that a file can be set to. And these modes/permissions are represented as follows:

—- r: this is the Linux permission to read-only.

—- w: this is the Linux permission to write only

—- x: this is the Linux permission to execute a file, and in the case of a directory, this permission is used to allow a user to search a directory.

THE SECOND chmod COMMAND SYNTAX.

chmod [options] [modeNumber] [fileName]

Each of the three Linux modes can be represented with numbers and they include:

4 = read

2 = write

1 = execute

0 = no permissions

Where u=rwx means 4 + 2 + 1 = 7

g = rw means 4 + 2 = 6

a = r means 4

Options.

—- chmod a=r file1.txt: this is used to change the permission of file1.txt to read-only for all users.

—- chmod u=rwx, g=r, o= filename: this option is used to give all of a file’s permission to the owner, give the read-only permission to users in the file’s group, and no permission to any other user.

—- chmod u=rw DirectoryName: this option is used to prevent a directory from being searched by the owner.

—- chmod 644 fileName: this option gives the owner only the read and write permission (4 + 2) and gives the group members and every other user only the read permission.

—- chmod 1777 dirName: this option gives all permissions to every file user and also adds a sticky bit flag to the said directory.

sudo command: sudo means Super User Do. It is a command that allows a user to carry out administrative tasks on a file. This is to say that with this command, you can perform some sensitive tasks without the need to log in as the file’s root user. In other words, this command allows a file to have multiple root users.

However, to be able to use the sudo command, you have to have all the necessary permission to modify the attributes of a file as the file’s owner. For security authentication purposes, the sudo command asks every user for a password that isn’t the root user’s password.

Syntax

sudo [command]

Options.

—- sudo -V: this option will display the version of the sudo command that your Linux system is using.

—- sudo -p: this option will allow a user to customize his/her password.

—- sudo -v: this option is used to extend the time you are permitted to use the sudo command. Usually, this option will extend your timestamp by five minutes and might ask you to re-enter your password before you continue.

—- sudo –l: it displays, in a list format, the sudo command (or options) that you are permitted to use, including the ones that you aren’t permitted to use.

—- sudo -h: this option will print all the help information and details that are associated with the sudo command.

—- sudo -u: this option will make the sudo command carry out a task as a normal user rather than as a sudo user. This means that this option contrasts the sudo command’s normal function.

—- sudo -k: this option is used to cancel a user’s sudo permission.

—- sudo -n: this option will prevent the sudo command from asking you to enter (or re-enter) your password. This can come in handy when you want to run a sudo command as a background process. So, use this option to avoid interruptions.

—- sudo –K: this option works like the “sudo -k” option, except that it also deletes the user’s timestamp.

kill command: this command, when used will forcibly terminate a process. But to do this, you need to pass the Process’s ID (PID) to the kill command as an argument. To find out a process’s ID, you can run the “$ps” command.

The kill command comes with a lot of signals, but I’ll only mention the three most common signals.

—- signal 15 or TERM: this signal will prompt the kill command to kill a process “gracefully”. This simply means that the kill command should wait for the process to save all its tasks before killing it.

—- signal 9 or KILL: this signal when given will prompt the kill command to close a process without waiting for it to save its tasks.

—- signal 1 or HUB: this signal will only make the kill command reload the said process.

Moreover, the kill command’s signals can be written in three different forms, and they include:

—- signal written with the signal number. Example: 15

—- signal written with its name and a SIG prefix. Example: SIGTERM

—- signal written only with its name. Example: TERM

Therefore, if a kill command is written as follows:

—- kill -15 PID

OR

—- kill -SIGTERM PID

OR

—- kill -TERM PID

It will carry out the same function of allowing a process to save its tasks before killing it.

Before we continue with the kill command’s syntax and options, I’ll like to tell you about process IDs in the Linux operating system.

Linux assigns a unique process identification number (PID) to every process, as a means to track and easily access those processes. Equally, the kill command carries out specific operations on a process based on the process’s ID. Here is an explicit explanation.

—- when the kill command is passed to a process whose PID is equal to -1, the kill command carries out the desired signal to that process and all other processes that share the same user ID with the user that sent the kill command (except the init process and the kill process itself).

—- when the kill command is passed to a process whose PID is less than -1, the kill command will carry out the desired kill signal to all the processes in the same group as the said process. That is to say that if the process with a PID that is less than -1 is in a group whose GID is 1000, then the kill signal will apply to all the processes in that same group.

—- when the kill command is passed to a process whose PID is greater than 0, then the kill command will carry out the desired kill signal to only that particular process.

—- when the kill command is passed to a process whose PID is equal to zero, then the kill signal will be applied to all the processes that are in the currently working directory.

Syntax

kill [options] [PID]

Options

—- sudo kill -1 PID: this option will reload the process whose PID was passed as the argument.

—- kill -l: this option will display all the kill signals that are available in your Linux system.

—- kill –L: this option will do the same task as “kill -l” above, however, it will display the kill signals that are available in your Linux system in a tabular form.

du command: du means disk usage, and just like its name implies, the du command is used to display information about the amount of disk space that a file is occupying. This command is very useful because you can use it to find out the file that is taking too much disk space and other related information.

The major downside of this command is that it displays information about a file’s disk usage in disk block numbers, which isn’t as human-readable as the kilobytes and megabytes that we are used to. Thankfully, the du command has an option that can be used to rectify this issue. Let’s begin, shall we?

Syntax.

du [option] [fileName]

Options

—- du -a: this option will display the disc usage of all the files and directories in your Linux system.

—- du -S: this option is used when you want to print the sizes and disk usage of all the directories in your Linux system, minus that of the sub-directories.

—- du –time: this du option will display the time that the file or directory that was passed as an argument was last modified.

—- du -c: this option will display a total sum of the sizes of the files in your system. This invariably tells you the amount of disc space that your files are occupying.

—- du -s: this option will summarize and display the size of your file and directories.

—- du -apparent-size: instead of displaying the disk space that every file occupies, this option will display each file’s apparent size.

—- du -h: this option will prompt the du command to display its results in a human-readable format.

—- du -B: this option will scale the apparent size of a file to SIZE before displaying it on the Linux shell.

echo command: this command is used to add texts or strings to an existing file. It displays those texts or strings that are passed into it as an argument.

Syntax

echo [option] [“string”]

OR

echo [options] [“argument”]

NOTE: For you to better understand the options of the echo command, I’ll use examples when needed.

Options

—- echo “coresonfire”: this option will display the text: coresonfire

—- echo -e “cores-on-fire”: this option will display the string that is passed to it without showing an error due to the special character (the backward slash).

—- echo -e “coresonfire rforum site”: this option will display the strings after the backward slash and r (r). Its output will be: forum site.

—- echo ‘ “coresonfire” ’ OR echo “ “coresonfire””: this option will display the text with a double quotation mark. Therefore, its output will be: “coresonfire”

—- echo -e “coresonfire” >> filename: this option will re-channel a text to the specified file instead of displaying it on the console.

—- echo -e “coresonfire bforum”: this option will display a string without white space. Therefore, its output will be: coresonfireforum

—- echo -e “coresonfire tforum”: this option will display a text in a horizontal form. However, instead of using normal white spaces to separate them, it will use the tab space wherever it finds the backward slash and t (t). Therefore, its output will be: coresonfire forum

—- echo *: this option works like the ls command (which we’ll discuss later on). It simply prints out all files and folders.

—- echo -e “coresonfire nforum”: this option will display all texts after the backward slash and n (n) in a new line. Therefore, its output will be:

Coresonfire

forum

—- echo -e “coresonfire aforum”: the letter a in this option stands for: alert. Therefore this option will display the above string with a sound alert.

—- echo -n “coresonfire”: this option will display the text or string that is passed to it, but it will eliminate all new lines. Therefore, the output will be: coresonfire

—- echo -e “coresonfire cForum” this option will display only the spring before the backward slash and c (c) and also eliminate any new lines. Therefore, the output will be: coresonfire

—- echo -e “coresonfire vforum vsite”; this option will display each string after the backward slash and v (v) in a new line and increases their tab spaces to produce a text that is slanted. The output of the above option will be:

Coresonfire

Forum

Site.

—- echo “I’m a Linux server admin” OR echo $‘I’m a Linux server admin’: this option will prevent the echo command from displaying an error when you pass a string that contains a single quote as an argument.

grep command: grep means Globally search for Regular Expression and Print out. This command searches through a file for a text or string and displays the result on the console.

Syntax

Grep [options] [pattern] [fileName]

Options

—- grep -I fileName: this option will search and display all the items that you searched for even the matched items that have a different case from the text that you passed as an argument.

—- the grep command has an option that will print lines that were searched before and after finding a matched text. This option is divided into three, and they include:

—- grep -A n: this option will display the lines that were searched after the result was found.

—- grep -B n: this option will display the lines that were searched before the result was found.

—- grep -C n: this option will display the lines that were searched before and after the result was found.

—- grep “^ textThatIsBeingSearched” fileName: this option will only print the lines that start with the “textThatIsBeingSearched”. For instance, grep “^command” will only display lines that start with the word: command.

—- grep -c fileName: this option will display the number of lines that contain the text/string that you are searching for.

—- grep -l: this option will display the names of files that contain the text of spring that you’re looking for in your current directory.

—- grep -o fileName: this option will print only the text that you’re searching for as they appear per line in a file. For instance, if an existing file: “What are the Linux commands and their functions?” contains only the first two paragraphs of this whole article. When you run the following grep command:

$ grep –o “command” What are the Linux commands and their functions.txt

The result will be:

command

command

command

command

command

It will print the word "command" 4 times (each of them, in a new line) which is exactly how many times that the word “command” was typed in the file (that is, the first two paragraphs of this article.

—- grep -v: this option will make the grep command print all the lines that don’t match the string that you’ve searched.

—- grep [string]$: this option will display all the lines that end with the string that you’re searching for.

—- grep -n: this option will print all the lines that contain the text that you’ve searched for, including their line numbers.

—- grep -w: this option is used to display the matched words in the sentence that they appear in.

mv command: mv stands for move, therefore this command is used to move files from one directory to another. Some websites explain the mv command as a command that is used to rename files in a Linux system.

However, this statement is only true when you’re relocating a single file to a new destination. We’ll discuss that in a bit.

Moving on, it might interest you to know that the mv command doesn’t ask for confirmation before moving a file. This trait can be disastrous if you want to move a file to a new destination that contains some content. If you’re not careful, the destination file might get overwritten, which is a situation that cannot be undone.

Syntax

mv [option] [source_dir/file] [destination_dir/file]

Options

—- mv –V: this option will display the version of the mv command that your Linux system is using, and also some related information.

—- mv -b [source_dir/file] [destination_dir/file]: this option will back-up the destination file before moving in the source file.

—- mv –u [sourcefile1] [sourceFile2] [destinationFile]: in this option, only the source file that is newer than the destination file is moved to the destination file.

—- mv -i [source_dir/file] [destination_dir/file]: this option will prompt the mv command to ask for confirmation before moving the source file to the destination file (applies only if the destination file exists).

—- mv [source_dir1/file1] [source_dir2/file2] [source_dir3/file3] [destination_dir/file]: this syntax will move many files to a destination file simultaneously.

—- mv -v: this option, when executed, will display all information about the source and destination files that are being moved.

—- mv [source_dir/file] [destination_dir/file]: this syntax will replace the filename of the source file with the filename of the destination file. However, if the destination file doesn’t exist, then the mv command will make the source file to be the destination. On the other hand, if the destination file exists, as I mentioned earlier, the mv command will simply overwrite its content. So, once again, please be careful while using the mv command.

—- mv -n [source_dir/file] [destination_dir/file]: this option will prevent the contents of an existing destination file from being overwritten. Rather, the source file will be appended to the destination file.

—- mv .[directoryExtention] [destinationFile/dir]: this option will move all the files from a directory to a destination file. For instance “$ mv .c file1.txt” will move all the files in the current directory (.c extension) to file1.txt.

—- mv -f [source_dir/file] [destination_dir/file]: this option is used to transfer a source file to a destination file if you don’t have the permission to write on the destination file. This mv option will forcefully overwrite the destination file.

diff command: diff means difference. The diff command is used to compare the contents of two files. Its function is basically to compare two files, line by line, display where they vary and give suggestions on how to make them similar. Note that, the diff command compares the first file against the second file. This is to say that it always tries to make the first file look like the second file.

This command comes in handy when you want to just make a few changes to a file, but don’t want to rewrite its whole contents. The diff command displays its result in codes (basically numbers and letters) as a means to pass suggestions on how to make the two files to be the same to you. I’ll explain those codes in a second.

—- a means to add

—- d means to delete

—- c means to change.

—- lines after the greater than symbol (>)refers to lines and content from the second line

—- lines after the less than symbol (<) refer to lines and content from the first line.

Don’t get confused, below is an instance of how the diff command works:

Imagine that we have two files, the first file, named Fruits1, and the second named Fruits2:

friits1

fruits2

cashew

watermelon

orange

cashew

carrot

banana

paw-paw

paw-paw

cucumber

orange

If the command “$ diff fruits1.txt fruits2.txt” is executed, the diff command will display:

0a1

watermelon

2,3c3

< orange

banana

5c5

orange

Output

Meaning

0a1

water melon

Here the diff command is telling you that you should ADD the content of line 1 in the fruits2 file (that is, watermelon) to line 0 in the fruits1 file. Line 0 simply means the line before line 1 in the fruits1 file.

2,3c3

< orange

banana

This means that you should CHANGE the content of lines 2 and 3 in the fruits1 file, starting from the text “orange”. Replace them with the text or content in line 3 of the fruits2 file, being the “banana” text.

5c5

Orange

This result means that you should CHANGE the text in line 5 of the fuits1 file to the text or content in line 5 of the fruits2 file.

Syntax

Diff [option] file1 file2

Options

—- diff -c file1 file2: this option will cause the diff command to display its result differently – in the context format. This time around, it will display without the letters and numbers, but with the minus and plus operators. Where the plus sign means to add a text to the respective line number in the other file, and the minus sign means to remove a text from a file.

For instance, if you have two files, fruits1, and fruits2, containing the same fruits as in the first example but arranged differently;

fruits1

fruits2

Cashew

cashew

Orange

paw-paw

Carrot

cucumber

paw-paw

Banana

If you run the following command:

“$ diff –c fruits1.txt fruits2.txt”, the result will be:

*1, 4****

cashew

-orange

-carrot

paw-paw

—1, 4——–

cashew

paw-paw

+cucumber

+banana

Result

Meaning

*1, 4****

File number one (fruits1), which contains four lines.

cashew

Notice that there are two white spaces before this line. This is to say that the diff command wants you not to change the text on this line.

-orange

-carrot

This means that you should remove these two lines from its file.

paw-paw

Two white spaces before this text mean that you shouldn’t change anything from this line.

—1, 4——–

This line indicates that the suggestions that will follow will concern file number two (fruits2).

Cashew

paw-paw

The white spaces before this text mean that you shouldn’t change anything from this line.

+cucumber

+banana

This means that you should add cucumber and banana to file number one (fruits2)

—- diff -u fruits1.txt fruits2.txt: this option will make the diff command display its results in yet another form, the unified format. Using the fruits1 and fruits2 files, below is an illustration of how the diff command looks in a unified format.

fruits1

fruits2

cashew

cashew

orange

paw-paw

carrot

cucumber

paw-paw

banana

If you run the following command “$ diff -u fruits1.txt fruits2.txt” on your system’s shell, the following will be the result.

—-fruits1.txt file modification date and time

***fruits2.txt file2 modification date and time.

@@ -1,4 +1,4 @@

cashew

-orange

-carrot

paw-paw

+cucumber

+banana

Notice that the only difference between this mode (the unified mode) and the context mode is that in the unified mode, the diff command, doesn’t repeat a suggestion. Be sure to scroll up and notice that in the unified mode, the diff command omitted the line numbers one and two of the second file suggestion.

That, and the fact that in the unified format, there’s room for the modification date and time of both files.

— diff -i: since the diff command is case sensitive, you can use this option to make it case insensitive.

—- diff -version: as always, this option will display the version of the diff command that’s running on your system.

chown command: this Linux command is used to change a file’s ownership and/or the group that a file belongs to. But it’s not as simple as that. The chown command has some…might I say, rules, that guide how it works, and below is an example.

—- while using the chown command, and you pass only the user name, then only the specified file’s ownership will be changed.

—- likewise, if you pass only the group name as an argument to the chown command, then only the file’s group will be changed to the group name that you specified

—- of course, if you pass only a colon (:), no user or group, then no file attribute will be changed.

—- if you pass the user’s name succeeded by a colon, then, first the file’s ownership will change, followed by changing the file’s group to the group of its new user.

—- if you pass the user’s name and a group, then both the file’s ownership and group will be changed to what you specified.

Before we continue with the syntax and options of the chown command, you’ll like to know that you can change a file’s ownership by passing the user ID as an argument, instead of using the new user’s name. For instance, “$ chown 2000 fileName” will change the ownership of “fileName” to the user with user ID 2000.

Syntax

Chown [option] [owner] [group] [fileName]

Options

—- chown -c: this option will display information about the time and date that a file’s ownership was modified.

—- chown –reference=file1 file2: this option is used to copy the ownership of one file and replace it with the ownership of the other file. In this case, the owner of the “file2” will be the exact duplicate of the ownership of “file1”

—- chown newUser:newGroup fileName: as I mentioned earlier, this option will change both the ownership and a file’s group to what you have passed as an argument.

—- chown -R newUser:newGroup dirName: this option will change the ownership and file groups of all the files in a directory, recursively.

—- sudo chown rootUser fileName: this option is used to change a file’s ownership to the root user.

—- chown newOwner:newGroup file1 file2 file3: this option is used to change the ownership and group of many files, simultaneously.

—- chown -f: this option will forcefully change a file’s ownership if you don’t have the permission to do that.

—- chown –from_oldOwner newOwner file OR chown n Owner fileName: these two options are used to change a file’s ownership.

curl command: in the Linux operating system, it’s the curl command that you can use to send or receive(download) files from a server (usually, the internet), using a supported protocol. These supported protocols include TFT-P, HTTP, LDAP, IMAP, SFTP, FTP, POP3, SCP, SMTP, TELNET.

In addition to this function, the curl command can run without human interaction, which simply means that it can run as a background process. Also, it can send and/or receive multiple files, simultaneously.

The curl command while receiving or sending files, usually displays a progress meter to show you the process’s progress. This progress meter usually contains information about the amount of data that has been sent or received, the time left for the process to be complete, the process’s transfer rate, user authentication (if need be), and so on.

Syntax:

Curl [options [url]

Options

—- curl –limit-rate [value] [url]: you can use this option to set a limit to the rate of data that the curl command will use while functioning. This is to say that the transfer rate’s upper bandwidth will not exceed the value (in B, KB, or MB) that you passed to the command.

—- curl -x [proxyName]:[port] [url]: this option allows you to use a proxy to send or receive files in the curl command. However, if the proxy needs to be verified, you should used the following command: “curl -u [user]:[password] -x[proxyName]:[port] [url]”

—- curl -b: this option makes it possible to store and send cookies to a server from the command line.

—- curl -o [fileName] [url]: this option will save the received file with the file name that you provided.

—- curl -C: this option is used to resume downloading in the curl command.

—- curl [protocol:dictionaryURL]:[word]: this option will help you to find the dictionary meaning of every word from the command line.

—- curl -L: this option will make the curl command follow all redirects in a URL until it reaches the file that you want to download.

—- curl -O [URL]: this option automatically saves the file that you download with the name that is in its URL.

—- curl -[SMTP URL] -[sender’sMail] -[receiver’sMail] -n -ssl -reqd -u{email}:{password} -T[mailText/File]: this curl command syntax is used to send a mail in the command line.

—- curl -s: this option tells the curl command to hide all error messages and the progress meter, making the curl command work in silence.

—- curl -u {userName}:{password} [FTPurl]: this option is used to download files from a verified FTP server.

—- curl -I: this option will get only the HTTP headers in a resource.

—- curl -u{userName}:{password} -T {fileName} {FTPLocation}: this option is used to send a file, in this case, the “fileName” to a verified FTP server.

cd command: the cd command is one of the basic and most frequently used Linux commands. It is a shell built-in command that you can use to switch to a new directory from the one you’re currently working in. With the cd command, you can also navigate to a subdirectory from the one that you’re currently working in.

Syntax

cd [options] [directory]

Options

—- “cd ..”: this option can be used to move from the currently working directory to the directory immediately before it. It can also suffice when you want to move from a subdirectory to the parent directory.

—- cd “directoryName” OR cd dirname: this option is used to move to a new directory whose name contains white space, single or double quote, or any special characters.

This option can also be joined with two other options to perform different tasks.

—- cd -L: this option makes the cd command change to a new directory and follow the directory’s symbolic link.

—- cd -P: this option works in contrast with the cd -L option above. It will cause the cd command to only change to physically named directories without following any symlinks.

—- cd ~ OR cd: this option will make the cd command move to the home directory.

—- cd/: this option will make the cd command move to the root directory.

—- cd-: this option will make the cd command move to the previously opened directory.

cp command: this Linux command is used to copy the content of a file in the current directory to another directory or file.

If the destination file or directory that you passed to the cp command exists and contains some content, the cp command will simply overwrite that file/directory. So, please be careful while using the cp command. On the other hand, if the destination file/directory doesn’t exist, the cp command will create it before pasting the contents of the source file/directory to it.

Syntax

—- cp [option] [sourceFile] : to copy content from a source file to the current directory.

—- cp [option] [sourceDirectory]: to copy content from a source directory to the current directory.

—- cp [option] [source1] [source2] [source_n]: to copy content from multiple sources to the current directory.

—- cp [option] [sourceDirectory] [destinationDirectory]: you can use this syntax to copy content from a directory to another. Remember, if the destination directory doesn’t exist, then the cp command will create the directory. On the other hand, if it exists, the cp command will add the content from the source directory as a subdirectory to the destination directory.

Options

—- cp -f: this option will cause the cp command to forcefully delete and overwrite the content of the destination file/directory. This usually occurs if the user in question has only the read permission to the destination file/directory.

—- cp -l: instead of copying the content of a file or directory, you can use this option to create a hard-link for the source file. A hard-link is a link that can be used to access a file even after the original file has been deleted.

—- cp -i: this option, when used, will prompt the cp command to ask for confirmation before overwriting an existing destination file/directory.

—- cp -R –v: this option will make the cp command display all the files whose content is currently copied.

—- cp -b: this option will prompt the cp command to create a backup file for the source file/directory.

—- cp -p: this option can be used (only) by a root user to display some vital attributes of a source file. Some of the information that this option displays include:

—- time that a file was last modified.

—- the time that a file was last accessed.

—- file ownership

—- a file’s permissions.

rm command: in a Linux system, the rm command is used to remove files that contain no content (empty files). Precisely, this command is used to remove the multiple references of a file. Usually, the rm command doesn’t display an option when its operation is successful, it only displays an error message if it encounters one. And like many other Linux commands, there’s no undo after you’ve hit the enter key to execute the rm command. Like I always say, please be careful.

Syntax

rm [option] [filename]

Options

—- rm — [fileName]: you can use this option to make the rm command remove an empty file whose filename is preceded by a hyphen (dash). For instance, “$ rm — -fileName.txt” will cause the rm command to remove the file named “-fileName”

—- rm -f: this option will make the rm command forcibly remove a file if you don’t have write permissions to the file. This option is, however, not applicable to directories.

—- rm -r OR rm -R: this option will make the rm command delete all the subdirectories in the target directory, recursively.

—- rm -i: this option will make the rm command ask for permission before removing a file.

df command: df means disk free. This command is used to display the disc space in a Linux system. It also shows how much of your disc space that your files, apps, and directories are using. The diff command displays its results in % and kilobytes and also shows your system’s available space.

Syntax

df [option] [fileName]

Options

—- df -T [fileName]: this option will cause the df command to print the file type of the file passed to it as an argument.

—- df -h: this option causes the df command to display file sizes in a human-readable format, that is, to the power of 1024.

—- df -l: this option makes the df command display information about files that are in the local system, only.

—- df -a: this option will make the df command display information about file sizes and the disc space that all files in a Linux system occupy. It also includes related details about duplicate files, synthetic files, and even inaccessible files.

—- df -H: this option is also used to display file sizes in human-readable form, but this time, it displays this information in the power of 1000.

—- df –total: this option will display the total of all the sizes and disc space of all the files in your Linux system.

tar command: the tar command which means tape archive command is a Linux command that is used to add and remove files/directories from a file archive.

An archive file is a file that contains multiple files and their metadata. An archive file is created majorly to save disc space and for easy transfer of files.

Syntax

tar [option] [archive] [fileToBeArchived]

Options

—- tar -r: this option is used to add a file to an existing file archive.

—- tar -f [name]: this option is used to create a file archive with a specific name (name).

—- tar xvf [fileArchive]: this option is used to extract all the files in a file archive.

—- tar –x [fileName] [fileArchive]: this option is used to extract a file from an archive file.

—- tar -z: this option is used to create a gzip archive file.

—- tar cvf fileArchive *.txt: this option is used to create an archive file and move all the .txt files in the current directory to the newly created archive.

—- tar -c: this option is used to create a new archive file.

—- tar -j: this option will make the tar command filter an archive file using the tbzip.

—- tar -A: this option will cause the tar command to join the content of two or more archive files.

—- tar -W: you can use this option to verify if an archive file exists.

—- tar -v: this option will cause the tar command to display verbose information about an archive.

jobs command: as its name implies, the job command is used to display all the jobs that are running in your Linux system – both the background and the foreground jobs.

Jobs are those background processes that are not daemons. Daemons on the other hand are those background processes whose duties are to monitor a Linux system’s functionality. These kinds of background processes are started and stopped either automatically (when your system is powered), or manually (by a server admin). In order words, the job command is used to display all the processes whose job isn’t to monitor your Linux system’s functioning.

Syntax

jobs [option] [job_ID]

Options

—- jobs -p: this option is used to display only the process IDs of all the currently running jobs.

—- jobs -l: this option is used to display the process IDs of all the currently running jobs, in addition to other related information.

—- jobs -n: this option will list jobs whose status has changed.

uname command: uname means Unix name. This Linux command displays detailed information about your Linux system and the hardware that you’re using. Some of the information that this command displays are: your system’s name, your processor’s operating system, your operating system’s kernel, and so on.

Syntax

uname [option]

Options

—- uname -n: this option will cause the uname command to display your system’s hostname, only.

—- uname -m: this option will display the name of your machine’s hardware.

—- uname (without an option) OR uname -s: these two options will only display the name of the kernel that you’re using.

—- uname -v: this option will display the kernel version that your Linux system is using.

—- uname -i: this option will cause the uname command to display your hardware’s platform.

—- uname -r: this option will display the date that your system’s kernel was released.

—- uname –p: this option will cause the uname command to display your system’s processor type.

—- uname -o: this option will make the uname command display the name of the operating system that your system is using.

zip, unzip command: in Linux command, the zip command is used to compress files to a zip archive file. And like an archive file, a zip archive file is a file that contains one or more compressed files. With a zip archive file, there’s no fear of losing a file’s data due to compression. Also, with a zip archive file, files are made smaller which in turn makes for easier and faster transfer.

On the other hand, the unzip command is the Linux command that you can use to extract a file from a zip archive file. Note that after the unzip command extracts files from a zip archive, it sends them to the currently running directory.

Syntax

zip [options] [zipfileName] [fileName]

unzip [zipfileName]

Options

—- zip -u [zipfileName] [fileName]: this option is used to compress a file to an existing zip archive.

—- zip -r [zipfileName] [directoryName] [directoryName]: this option will cause the zip file to compress the files in a directory, recursively.

—- unzip [zipfileName] [directoryName] -x [fileToBe_Excluded]: this option should be used when you want to unzip files from a directory, but you want to exclude a particular file.

—- unzip -l [zipFilename]: instead of unzipping a file in a zip archive, this option will cause the unzip command to display the names of the files that are in a zip archive in a list format.

—- zip -d [zipfileName] [fileName]: this option can be used to delete a particular file from a zip archive.

—- zip -x [zipfileName] [fileToBe_Excluded]: like its unzip counterpart, this option is used to exclude a file from being compressed.

—- unzip -q [zipfileName]: while the zip command is running, it displays the names and a summarized description of the files that it is compressing, you can therefore use this option to prevent that summary and name(s) from showing.

—- unzip -o [zipfileName]: this option is used to overwrite an unzipped file.

—- zip [zipfileName] [file1] [file2] [file3]: you can use this option to compress more than one file to an empty zip archive file. If the zip archive isn’t empty, it will be overwritten.

—- zip -m [zipfileName] [directoryName]: this option is used to compress a file from the given directory to a zip archive file. After this transfer, the zip command deletes the said file from the directory. If, however, the directory becomes empty after the file has been compressed, then the zip command will delete the directory.

—- unzip [zipfileName] -d [directoryPath]: remember that the unzip command extracts a file (or many files) from a zip archive to the currently running directory. Well, with this option, you can cause the unzip command to extract a file and send it to a different directory.

—- unzip -n [zipfileName]: this option will make the unzip command unzip files without overwriting the destination directory.

—- unzip [zipfileName]: like I already indicated in its syntax, this is used to extract or restore a file from a zip archive file.

—- unzip -P [password] [fileName]: this is the option that you can use if you want to unzip a file that is protected with a password. You can also do this by unzipping the file like you do any other file, while this process is running, the unzip file will ask you to input its password.

ls command: the ls command is one of the most commonly used Linux commands. It is used to view all the files and subdirectories that are present in the currently working directory. The ls command has a lot of options that we don’t usually know of. Below are its syntax and some of its most important options.

Syntax

ls [option] [files]

Options

— ls -t: this option will cause the ls command to show all the files in the currently working directory according to the date and time that they were last modified.

—- ls -s: this option will make the ls command display all the files in a directory according to their sizes.

—- ls -l -h -s -r: this bizarre-looking option is used to reverse the sort order that you gave to your Linux system.

—- ls -R: this option will cause the ls command to display all the files in a sub-directory, recursively.

—- ls *: if you want to perform an action on multiple files, use this option.

—- ls -t -h -s: this option is used to sort a list of files from the biggest to the smallest.

— ls -t/tail -1: this option will cause the ls command to display the oldest file in the currently running directory.

—- ls -a: this option is used to display all hidden commands and files in your system.

—- ls -I -h: this option will cause the ls command to display the sizes of files in your system in a human-readable form.

—- ls -n: this option will cause the ls command to display the user ID (UID) and the group ID (GID) of all the files in the currently working directory.

—- ls -t/head -1: this option will cause the ls command to display the newest file in the currently running directory.

—- ls -al: this option will make the ls command display all the files and subdirectories in the currently running directory including detailed information about them.

—- ls -I: this option is used to display detailed information about the currently working directory.

—- ls -X: this option is used to sort files on a list using the extension option.

alias command: this command can be described as a command’s shortcut. You know how you only have to click a file’s shortcut on your desktop to access the file, it is also applicable to commands with the help of the alias command.

In a situation where you’re always running the same command frequently, instead of always rewriting the said command, you can use an alias and the alias command to call that command to run. This is to say that whenever you type the alias together with the alias command and hit the enter key, that particular command that you want will start running.

Syntax

The syntax for creating an alias is: alias [aliasName]="command”

The syntax for removing an alias is: ualias [aliasName]

Options

—- alias -p: this option will display all aliases in your system in a re-usable format.

—- alias –help: you can use the help option to get more information about the alias command.

cat command: cat means concatenate. This frequently used Linux is used to display the content of a file.

Syntax

cat [option] [file]

Options

—- cat [fileName]: this option is used to display the content of a file.

—- cat [file1] [file2] [file3]: this option is used to display the contents of multiple files.

—- cat -n [fileName]: you can use this option to display the contents of a file in a numbered list.

—- cat -E [fileName]: this option will make the cat command highlight the last line in a file’s content.

—- cat [filename] |more: if the content of a file is so much that all of it cannot enter your console at once, you can use this option to prompt the cat command to show you the other part of the file’s content that you can’t see.

—- cat > [fileName]: this option is used to create a new file.

—- cat -s: this option will make the cat command remove all the empty lines while displaying the content of a file.

—- cat >> [fileName]: this option can be used to append the cat command to an existing file. This is to say that you can use this option to add text to an existing file using the cat command.

—- cat [file1] [file2]>[file3]: this option is used to join the content of two files to a third file. In this case, the content of file1 and file2 are joined and moved to a newly created file3.

—- tac [fileName]: this option is used to display the contents of a file in a reverse form. When the word “cat” is spelled backward, you get “tac”.

—- cat [fileName]>[destinationFile]: this option will make the cat command copy the contents of a file to a destination file.

—- cat — [file-Name]: this option is used to print the contents of a dashed file.

—- cat [file1]>>[file2]: this option is used to join the contents of two files. In this option, the content of file2 is added to the beginning of file1.

mkdir command: where mkdir means make directory. This Linux command is used to create one or more new directories.

Syntax

mkdir [option] [directory]: to create a new directory.

mkdir [option] [directory1] [directory2]: to create multiple directories at once.

Options

—- mkdir –v: this option is used to view all relevant details and the current status of the currently working directory. You can also use this option to check if the renaming, moving, or creating of a new directory was executed successfully.

—- mkdir –version: this option will display the version of mkdir that your Linux system is using.

—- mkdir -m: this option is used to set the mode of a newly-created directory.

—- mkdir -m a=rwx dirName: this option is used to set the mode of a directory to read, write and execute, for all users.

—- mkdire -m a=r dirName: this option will set the mode of a new directory to read-only, for all users, and so on.

—- mkdir –help: this option will display all the available help options for the mkdir command on your console.

—- mkdir -p: this option is used to create parent directories.

touch command: the touch command is a Linux command that is used to create a blank file snd to update a file’s timestamp. A file’s timestamp is simply information on when a file was last accessed, modified, and other related information.

In Linux operating system, every file has three timestamps, and they include:

—- access time: the last time that a file was opened.

—- modification time: the last time that the contents of a file were changed or worked on.

—- change time: the last time that a file’s attributes (like permission, ownership, etc.) were changed.

Note that the touch command will only create a new file if the file doesn’t exist on your Linux system. If the file that was passed to it as an argument exists, then the touch command will simply change the file’s timestamp. The touch command can also be used to change the timestamp of soft links (symbolic links)

Syntax

touch [fileName]

Options

—- touch -a [fileName]: this option is used to change a file’s timestamp.

—- touch -r [file1] [file2]: this option is used to copy the timestamp of one file and use it to update another file’s timestamp. In this case, file1’s timestamp will be updated with file2’s timestamp.

—- touch file1 file3 file3: this syntax is used to create multiple blank files.

—- touch -m [fileName]: this option is used to change a file’s modification time only.

—- touch -c -d: this option will make the touch command change a file’s access and modification time.

—- touch -t YrMnDaHrMnSec [filename] OR touch -d YrMnDaHrMnSec [filename]: this option will make the touch command to create a file with a specific time. Note that if you pass only the date as an argument, the touch command will set the new file’s year to the current year.

—- touch -c [fileName]: this option will prevent the touch command from creating a file even if the file doesn’t exist.

head command: by default, the head command is used to display the first 10 lines of the content of a file.

Syntax

head [option] [file]

Options

—- head -q file1 file2: this option is used to display the first 10 lines of file1 followed by the first 10 lines of file2.

—- head -v: this option will make the head command display a file’s name before printing the first 10 lines of its content.

—- head -n [desiredNumberOfLines]: instead of printing the first 10 lines of a file’s content, this option will make the head command print the number of the line that you passed to it. for instance, “$ head -n 4 coresonfire.txt” will make the head command to print the first four lines of the content of the coresonfire file.

—- head -c [desiredNumberOfCharacterToDisplay]: this option will make the head command print a specific number of characters/bytes from the beginning of a file’s content. Note that white space is counted as a byte. An example is passing this head option to your Linux system: “$ head -c 15 coresonfire.txt”. This command will display: “What are the L” which is the first 15 characters in this file (article).

tail command: this command is the opposite of the head command. By default, it is used to display the last 10 lines of a file’s content.

Syntax

tail [option] [file]

Options

—- tail +[number]: if the “number” in this option is 25, this option will make the tail command display only line 25 of a file’s content.

—- tail -q: this option will make the tail command display the last 10 lines of two files without separating them with their filenames. For instance, if file1 contains numbers from 1 to 50 and file 2 contains all the letters of the alphabet.

—- If you execute a tail command for the two files, without the –q option, “$ tail file1.txt file2.txt”. This will be the result:

file1.txt

41

42

43

44

45

46

47

48

49

50

file2.txt

q

r

s

t

u

v

w

x

y

z

—-if the –q option was used, “$ tail -q file1.txt file2.txt”, this will be the output:

41

42

43

44

45

46

47

48

49

50

q

r

s

t

u

v

w

x

y

z

—- tail -f: this tail option is used by system admins to keep track of file logs. This option will display the last 10 files that were added and will notify you if new files are added.

—- tail -n [number]: this option will print the number of lines that you specified, from the bottom of the file’s content.

—- tail –version: this option will display the tail version that your Linux system is using.

—- tail -c [number]: this option will display the specified number of characters from the last line of a file’s content. This option can be used in two different ways:

—- tail –c –[number]: if the number passed as the argument is 6, this option will display the last 6 characters in a file’s content.

—- tail -c +[number]: if the number passes as the argument is 500, the tail command will display all the characters after the first 500 characters in a file’s content.

ping command: ping means packet internet groper. The function of this Linux command is to measure your system’s connectivity to a server. It also measures the time it takes your system to connect to a server, the time it takes for the server to grant your system’s result and the time it takes for your system to get the needed result.

This, it does by sending out data packets that contain your system’s IP address (or URL) accompanied by the PING command. The ping command displays its result in milliseconds. Note that a fast ping and a low response time (also called latency) means that a system has fast connectivity.

The ping command comes in handy when you want to troubleshoot or check for the cause of your system’s network problem. Note also, that the ping command sends data packets for as long as it is running until you make or force it to stop. You can do this externally by pressing the Ctrl+C keys.

Syntax

ping [option] [destination]

Options

—- ping -c [numberOfPackets] [URL or IP address]: by default, the ping command sends data packets, unendingly. But with this option, you can tell it the specific number of packets that you want to send to the server.

—- ping -T: you can use this option to record a timestamp while checking your system’s connectivity. This option is further divided into three:

—- ping -T tsonly: this option will make the ping command record a timestamp only.

—- ping -T tsprespec: this option will make the ping command record a timestamp for all multiple hosts that you have specified.

—- ping -s [number]: this option will limit the size of the data packet that the ping command will send to the number that you passed to it.

—- ping -i [numberOfsec] [URL or IP address]: this option tells the ping command to send packets after a specified number of seconds. This is to say that this option allows you to dictate the time intervals between each data packet.

—- ping -q: this option, when used, will make the ping command print only summarized information about a network.

—- ping -t [number]: this option allows you to set the specific distance that a data packet can live (or travel) before it is discarded.

—- ping -w [number] [URL or IP address]: remember that the ping command sends packets unendingly until you make it stop. You can also use this option to tell the ping command how long (time measured in seconds) it should send packets before it stops.

—- ping -f: this option will make the ping command send packets immediately (as soon as possible).

—- sudo ping -v: this option will display the ping version that your system is currently using.

Conclusion

There are more than 30 Linux commands that are in use, but for want of space and time, I’ll have to stop here. Remember that you can use the first command in this article, the “man command” to view all Linux commands. This command will also display their syntax and all its available options.