TeachingBee

10 Basic Linux Commands: A Beginner’s Guide to the Command Line

basic linux commands

When we hear about Linux the majority of people imagine a complex operating system solely utilised by programmers. However, it’s not as terrifying as it appears.

Linux is a complete collection that includes open source Unix operating systems which are built in the Linux Kernel. This includes all the most well-known Linux operating systems, such as Ubuntu, Fedora, Mint, Debian, and others. In more precise terms, they’re referred to as distros or distributions.

The majority of Linux distributions utilize the graphic user interface (GUI) for their shells, in order to facilitate use to their customers.

It’s advised to use a command line interface (CLI) as it’s faster and more effective. The tasks that require an extensive process using GUI can be accomplished in just a few seconds through typing instructions into CLI.

In this tutorial on linux commands we will see basic linux commands that every programmer should know.

Syntax

The basic Linux commands have the following syntax:

$ command options arguments

ls

List (ls) command is similar of DOS DIR, as it lists down directories and files and is one of the most basic linux commands frequently used. If you type ls at command line you’ll be able to see all the non-hidden files that are in your present directory.

It’s true that the command ls command won’t reveal the entire home directory on a brand new operating system. Let’s look at directories and files that /etc directory conatins. The directory /etc directory is where the Linux system’s configuration data is stored.

$ ls /etc
basic linux commands
ls command output

You’ve successfully listed all the content of your the /etc directory, however you can also show files in various ways. 

Above, I mentioned non-hidden files. If you have a home directory in which you are currently likely to have hidden files. Files that are hidden in Linux begin with a dot( .). For instance, you probably have an .bash_profile file there. To check it out, run this ls command with -a option.

$ ls -a

The -a option, as it’s referred to shows you every the files, including those hidden.

man

Linux comes with a vast set of online documentation available for your information related to advance and basic linux commands. They’re called manual pages, meaning you can read the manual. The abbreviated phrase for referring to the manual is man command and a large screen and a screen of information appears in front of you.It’s simple to navigate through man pages. 

Here’s the most important keys when viewing man page.

KeysFunction
fpage down
bpage up
hshow help
qexit/quit
type /str=search
nnext occurrence
Nprevious occurrence

For an example take a look at the man page of ls command.

$ man ls
basic of linux commands
man ls command Output

cat

This cat command is crucial as a fundamental and basic linux commands since it performs two crucial purposes that include concatenating (merging) file files (as the name implies) and printing information from a file onto the screen. The printing of the content from files is the most frequently used application for this option. If you’d like to view the contents of a document, make use of the following format:

$ cat filename

To make use of cat to concatenate files using its capabilities, the basic version that is used for this command can be described as:

cat file1.txt file2.txt > file3.txt

You can join the number of files you like into one file with cat command

touch

Touch command is another command that serves a dual purpose. "touch" command is a different one that has a dual function. Its purpose is to alter the timestamps of files. 

To list the contents of an entire directory in long format, you can do this by:

$ ls -l

The output of the command shows the ownership, permissions size, creation date/time, most recently accessed date/time, as well as the filename.

Use the touch command to change the last access timestamp

$ touch file.txt

By default, if no option is used touch will update the file last access and modification times to the current time. By using the -a and -m options, you can change only one of these timestamps.

Change only the access time

Use the -a option to change only the file’s access time:

touch -a file.txt

Change only the modify time

Use the -m option to change the file’s modify time:

touch -m file.txt

When changing the modify time, the change time will be also updated.

Utilising touch command to update the last visited time is a very rare usage that this option. The most common usage for the touch command can be to make a blank file to serve as placeholder. Certain applications require a specific file in order to function properly that’s one method to start the process. In other words, this method offers the possibility of quickly creating files without having to open the text editor, and saving a blank file.

$ touch blankfile.txt

If the file “blankfile.txt” doesn’t exist the following command will create it otherwise, it will change its timestamps:

pwd

The pwd command is the Linux system’s compass. It’s the reason that it will tell you exactly where you are. It is not doing anything other apart from providing this piece of data to the user. Running following command will give you current working directory.

$ pwd

If you’re lost, or simply wonder which part of the filesystem it is this command to tell you where to go. Linux users frequently use it when removing or altering files to make sure of their current whereabouts.

The pwd command will always show the complete route to your destination, regardless of whether you’re several directories away of the base (/) directory.

cd

Moving directories is a common task when using an Linux system. To move to different directory cd command can be used along with target directory relative or absolute path

$ cd /targetDirectoryPath

The quickest way to go back to base directory is to use dot(.) with cd command

$ cd .

To switch directory to one that is above your current directory, you can use Double period (dot) option:

$ cd ..

Now you’re within the now in the /usr directory. Be aware that you are able to “prove” your location to yourself by executing the command pwd: command:

rm

Next in the list of basic of linux commands is rm command. It is the rm command that is used to remove (deletes) directories and files. 

rm deletefile.txt

Did you observe that you didn’t get any prompts or questions? Linux presumes you already know what you’d like to accomplish before hitting Enter. You can get around this non-interactive behaviour of certain commands by adding "-i switch (option) before the command. Check out the following example:

touch $ blankfile.txt
$ rm -i newfile.txt

rm: Remove the blank files 'newfile.txt '?

"-i" makes the rm interactive. Answer by saying "Y", and your file is deleted away. Answer by using an "n" and you will keep the file. To ensure your safety it is always possible to make use of to use the "i" switch to the rm command. Similarly to recursively rm subdirectories use -r option.

cp

The process of copying directories and files is a common job for Linux administrators and that is where cp command comes handy. To use this command you need to specify the source path, and then the destination path

cp sourcefilepath destinationfilepath

To copy a directory, and its entire contents including subdirectories, you can use your option -R (Recurse) choice.

$ cp -R sourceDirectoryPath destinationDirectoryPath

You can also make use of wildcards while creating copies to sort them using patterns:

$ cp *.txt /textfileDirectory

mkdir

It’s simple to make directories. You can use the mkdir command, followed by the name of the directory you want to create:

$ mkdir data

It is also possible to create directories at the same time simultaneously.

$ mkdir dir1 dir2 dir3

ps

The final most basic Linux commands you should be aware is ps command This command will show you the currently running processes. When you run this the ps command, you’ll only see the processes you have created.

If you’re running nothing and this output isn’t very fascinating. It’s much more fascinating to know what’s happening across the entire system. This can be done by adding options to ps command.

 The most effective options are the -e as well as -f.  To extract the most data through this ps command, you can combine two options in this command.

$ ps -ef

The fields are easy to grasp and are useful in diagnosing performance issues:

FieldDescription
CCPU Usage.
CMDThe process or command name, along with the path.
PIDProcess ID.
PPIDThe parent Process ID It is this process that initiated the process.
STIMEStart The process will begin at the time indicated.
TIMECPU Time required for this process.
TTYThe user terminal that initiated the process. The system process will be displayed by question mark (?) .
UIDThe ID for the user of owner of the process.

Conclusion

These are the 10 most basic Linux commands you should be aware of. There’s no one command that’s more important than another. All of them are important and each useful. I picked these because they’re the top 10 basic linux commands that everybody regularly utilises, whether you’re a novice or an experienced admin and therefore are must to know for any developer.

Got a question or just want to chat? Comment below or drop by our forums, where a bunch of the friendliest people you’ll ever run into will be happy to help you out!

90% of Tech Recruiters Judge This In Seconds! 👩‍💻🔍

Don’t let your resume be the weak link. Discover how to make a strong first impression with our free technical resume review!

Related Articles

difference between pert and cpm

What is Difference Between PERT and CPM

Project management methodologies like Program Evaluation and Review Technique (PERT) and Critical Path Method (CPM) are widely used for planning, scheduling and monitoring complex projects. Both PERT and CPM are

Why Aren’t You Getting Interview Calls? 📞❌

It might just be your resume. Let us pinpoint the problem for free and supercharge your job search. 

Newsletter

Don’t miss out! Subscribe now

Log In