Linux is a family of open-source Unix-like operating systems based on the Linux kernel. It is typically packaged in a Linux distribution for supporting system software and libraries, many of which are provided by the GNU Project, allowing modifications to the original software. Popular Linux distributions include Debian, Fedora, Centos, OpenSUSE Arch Linux, Ubuntu and many others. Because Linux is freely redistributable, anyone may create a distribution for any purpose.
The Linux command line is a case sensitive text interface to accomplish all administrative tasks to your computer system. All the commands are run in the terminal provided by the Linux system.
The terminal is a user interactive and outputs the results of commands which are specified by the user itself. Execution of typed command is done only after you press the Enter key. It has the power and flexibility, means that using it may be essential when trying to follow instructions online.
Here are the most used Linux basic commands:
alias command is to instructs the shell to replace one string with another string while executing the commands. It lets you give your own name to a command or sequence of commands.
You can then type your short name, and the shell will execute the command or sequence of commands for you.
cat command is to lists the contents of files on the standard output to the terminal window. It is one of the most frequently used commands in Linux. This is faster than opening the file in an editor, and there’s no chance you can accidentally alter the file.
cd command is to changes your current working directory. In other words, it moves you to a new place in the file system.
If you are changing to a directory that is within your current directory, you can simply type cd and the name of the other directory.
cp command is used to copy files or group of files or directory from the current directory to a different directory.
chmod command is to change the access mode of a file. It sets the file permissions flags on a file or folder including read, write, and execute permissions of files and directories.
chown command is to allows you to change the owner and group owner of a file. All files are owned by a specific user. This command enables you to change or transfer the ownership of a file to the specified username.
clear command is used to clean out the terminal screen if it is getting cluttered with too many past commands.
curl command is a tool to retrieve information and files from Uniform Resource Locators (URLs) or internet addresses or to transfer data to or from a server, using any of the supported protocols
curl command may not be provided as a standard part of your Linux distribution. Use “apt-get” to install this package onto your system if you’re using Ubuntu or another Debian-based distribution. On other Linux distributions, use your Linux distribution’s package management tool instead.
df command is to shows the size, used space usage, and available space on the mounted file systems of your computer. It will display information related to file systems about total space and available space, shown in percentage and kilobytes.
If you want to see the report in megabytes, type “df -m”.
The diff command is to display the differences in the files or to compares two text files and shows the differences between them line by line.
There are many options to tailor the display to your requirements. After analyzing the files, it will output the lines that do not match. Users often use this command when they need to make program alterations instead of rewriting the entire source code.
du command is used to track the files and directories which are consuming excessive amount of space on storage device. The disk usage summary will show disk block numbers instead of the usual size format.
If you want to see it in bytes, kilobytes, and megabytes, add the “-h” argument to the command line.
echo command is to prints (echoes) or display line of text/string that are passed as an argument to the terminal window. It can show the value of environment variables, for example, the “$USER”, “$HOME”, and “$PATH” environment variables.
These hold the values of the name of the user, the user’s home directory, and the path searched for matching commands when the user types something on the command line.
exit command is used to exit or close a currently running terminal window, end the execution of a shell script, or log you out of an “SSH” remote access session.
find command is to find files and directories and perform subsequent operations on them. It tracks down files that you know exist if you can’t remember where you put them.
Similar to the “locate command”, using find also searches for files and directories. The difference is, this command locate files within a given directory.
finger command is used to gives you a short dump of information about a user. It is a lookup command which gives details of all the users logged in including the time of the user’s last login, the user’s home directory, and the user account’s full name.
free command is to displays the total amount of free space available along with the amount of RAM (Random Access Memory) used and swap memory in the system, and also the buffers used by the kernel. It gives you a summary of the memory usage with your computer.
The “-h” (human) option is used to provide human-friendly numbers and units. Without this option, the figures are presented in bytes.
grep command is to searches a file for a particular pattern of characters, and displays all lines that contain that word or pattern. It lets you search the contents through all the text in a given file. This is helpful for everyday use.
groups command is used to tells you which groups a user is a member of. Groups are the collection of users. Groups make it easy to manage users with the same security and access privileges
gzip command is used to compresses files. Each single file is compressed into a single file. By default, it removes the original file and leaves you with the compressed version. To retain both the original and the compressed version, use the “-k” (keep) option.
head command is used to view the first lines of any text file. It also gives you a listing of the first 10 lines of a file. It prints the top “N” number of data of the given input.
By default, it will show the first ten lines, but you can change this number to your liking. For example, if you only want to show the first five lines, type head -n 5 filename.ext.
history command is to lists the commands you have previously issued or executed on the command line. You can repeat any of the commands from your history by typing an exclamation point and the number of the command from the history list.
When you’ve been using Linux for a certain period of time, you’ll quickly notice that you can run hundreds of commands every day. As such, running history command is particularly useful if you want to review the commands you’ve entered before.
hostname command is used to knows the name of your host/network. It obtains the DNS(Domain Name System) name and set the system’s hostname or NIS(Network Information System) domain name.
Adding a “-I” to the end will display the IP address of your network.
less command is to allows you to view files without opening an editor. It reads contents of text file one page (one screen) per time. It’s faster to use, and there’s no chance of you inadvertently modifying the file.
With less you can scroll forward and backward through the file using the Up and Down Arrow keys, the “PgUp”, “PgDn”, “Home” and “End” keys. Press the “Q” key to quit from less.
locate command is to find or locate a file by name that contains two or more words, use an asterisk (*).
Using the “-i” argument along with this command will make it case-insensitive, so you can search for a file even if you don’t remember its exact name, whether it is uppercase or lowercase.
ls command is used to view the contents of a directory. It lists the files and folders in the directory you specify and there are variations you can use with this command.
By default, this command will display the contents of your current working directory. There are a great many options you can use with ls , and we strongly advise reviewing its the man page. Some common examples are presented here.
man command is to displays the user manual of any command that we can run on the terminal. For instance, entering man tail will show the manual instruction of the tail command.
mkdir command is to allows you to create new directories in the file system. This command can create multiple directories at once.
You must provide the name of the new directory to mkdir. If the new directory is not going to be within the current directory, you must provide the path to the new directory.
mv command is used to allows you to move one or more files or directories from one place to another directory. The primary use of the mv command is to move files, although it can also be used to rename files.
The arguments in mv are similar to the cp command. You need to type mv, the file’s name, and the destination’s directory. To move a file you must tell mv where the file is and where you want it to be moved to.
passwd command is used to lets you change the password for any user.
You can also change the password of another user account, but you must use sudo. Just type passwd to change your own password. You will be asked to enter the new password twice.
ping command is to lets you check the network connectivity status between host and server/host or with another network device. It is commonly used to help troubleshoot networking issues.
To use ping, provide the IP address or machine name of the other device. For example, by simply entering ping google.com, the command will check whether you’re able to connect to Google and also measure the response time.
ps command is used to lists running processes and their “PIDs” along with some other information depends on different options. Using ps without any options will make it to list the processes running in the current shell.
pwd command is used to find out the path of the current working directory (folder) from the root / directory. This command will return an absolute (full) path, which is basically a path of all the directories that starts with a forward slash (/). An example of an absolute path is /home/username.
rm command is used to delete objects such as files, directories, symbolic links and the contents within them from the file system.
rmdir command is used to delete a directory. However, it only allows you to delete empty directories in the file system.
shutdown command is to lets you shutdown or reboot your Linux system in a safe way.
ssh command is to make a secure connection to a remote Linux computer and log into your account. To make a connection, you must provide your user name and the IP address or domain name of the remote computer.
sudo command is required when performing actions that require root or superuser permissions. It used as a prefix of some command that only superuser are allowed to run such as changing the password for another user.
tail command is used to gives you a listing of the last 10 lines of a file. This command has a similar function to the “head” command, but instead of showing the first lines, the tail command will display the last 10 lines of a text file.
If you want to see fewer or more lines, use the “-n” (number) option. In this example, we use tail with its default of 10 lines. We then repeat the command asking for only five lines.
tar command is to create an archive and extract the Archive file that can contain many other files. This makes it much more convenient to distribute a collection of files. It is common to ask tar to compress the archive. If you do not ask for compression, the archive file is created uncompressed.
The tar is a common Linux file format that is similar to zip format, with compression being optional.
top command is used to shows you a dynamic real-time display of the data relating to your Linux machine. It will display a list of running processes and how much CPU each process uses. It’s very useful to monitor system resource usage.
The top of the screen is a status summary. It shows you the time and how long your computer has been running for, how many users are logged into it, and what the load average has been over the past one, five, and fifteen minutes.
uname is used to displays the information about the system.
You can obtain some system information regarding the Linux computer you’re working on with the uname command.
unzip command is used to extract the zipped files from a zip archive.
useradd command is used to create a new user, while “passwd” is adding a password to that user’s account. This means more than one person can interact with the same system at the same time.
userdel command is used to delete a user account and related files, while “useradd” is used to create a new user
wget command is used to download files from the server even when the user has not logged on to the system and it can work in background without hindering the current process.
whoami command is used to find out who you are logged in as or who is logged into an unmanned Linux terminal. It displays the username of the current user when this command is invoked
zip command is used to compress your files into a zip archive, while “unzip” command is to extract the zipped files from a zip archive.
Tips: Linux Basic Command on Terminal
Learning Linux basic command line is like learning anything else. You’re going to need some practice before become familiar with the above mentioned commands. Once you familiar with these commands with Terminal, you will be well along the path to proficiency.
“Ctrl+Shift+C” keyboard buttons can copy marked text on the terminal, while “Ctrl+Shift+V” buttons will paste the copied text on the terminal.
“Ctrl+C” and “Ctrl+Z” are used to stop any command that is currently working. “Ctrl+C” will stop and terminate the command, while “Ctrl+Z” will simply pause the command.
If you accidental freeze your terminal by using “Ctrl+S”, you can undo this with the unfreeze “Ctrl+Q”.
“Ctrl+A” moves you to the beginning of the line, while “Ctrl+E” moves you to the end.