Linux Basic Commands
Linux Basic Commands
1. pwd command
Use the pwd command to find out the path of the current working directory
(folder) you’re in. The 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.
2. cd command
To navigate through the Linux files and directories, use the cd command. It
requires either the full path or the name of the directory, depending on the
current working directory that you’re in.
Let’s say you’re in /home/username/Documents and you want to go
to Photos, a subdirectory of Documents. To do so, simply type the
following command: cd Photos.
Another scenario is if you want to switch to a completely new directory, for
example,/home/username/Movies. In this case, you have to
type cd followed by the directory’s absolute path: cd
/home/username/Movies.
There are some shortcuts to help you navigate quickly:
3. ls command
The ls command is used to view the contents of a directory. By default, this
command will display the contents of your current working directory.
If you want to see the content of other directories, type ls and then the
directory’s path. For example, enter ls /home/username/Documents to
view the content of Documents.
There are variations you can use with the ls command:
4. cat command
cat (short for concatenate) is one of the most frequently used commands in
Linux. It is used to list the contents of a file on the standard output (sdout).
To run this command, type cat followed by the file’s name and its
extension. For instance: cat file.txt.
Here are other ways to use the cat command:
6. mv command
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. For example: mv file.txt
/home/username/Documents.
To rename files, the Linux command is mv oldname.ext newname.ext
7. mkdir command
Use mkdir command to make a new directory — if you type mkdir Music it
will create a directory called Music.
There are extra mkdir commands as well:
8. rmdir command
If you need to delete a directory, use the rmdir command. However, rmdir
only allows you to delete empty directories.
9. rm command
The rm command is used to delete directories and the contents within
them. If you only want to delete the directory — as an alternative to rmdir
— use rm -r.
Note: Be very careful with this command and double-check which directory
you are in. This will delete everything and there is no undo.
15. df command
Use df command to get a report on the system’s disk space usage, shown
in percentage and KBs. If you want to see the report in megabytes, type df
-m.
16. du command
If you want to check how much space a file or a directory takes,
the du (Disk Usage) command is the answer. However, 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.
17. head command
The head command is used to view the first lines of any text file. 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.