Linuxcommandspdf 2023 01 30 09 18 34
Linuxcommandspdf 2023 01 30 09 18 34
https://www.onlinegdb.com/online_bash_shell
Linux Terminal:
https://www.webminal.org/register/
List of basic Linux commands with example
https://www.javatpoint.com/linux-commands
1. sudo command
Short for superuser do, sudo is one of the most popular basic Linux
commands that lets you perform tasks that require administrative or root
permissions.
When using sudo, the system will prompt users to authenticate
themselves with a password. Then, the Linux system will log a
timestamp as a tracker. By default, every root user can run sudo
commands for 15 minutes/session.
If you try to run sudo in the command line without authenticating
yourself, the system will log the activity as a security event.
Here’s the general syntax:
sudo (command)
You can also add an option, such as:
2. pwd command
Use the pwd command to find the path of your current working
directory. Simply entering pwd will return the full current path – a path of
all the directories that starts with a forward slash (/). For
example, /home/username.
The pwd command uses the following syntax:
pwd [option]
It has two acceptable options:
3. cd command
To navigate through the Linux files and directories, use
the cd command. Depending on your current working directory, it
requires either the full path or the directory name.
Running this command without an option will take you to the home
folder. Keep in mind that only users with sudo privileges can execute it.
Let’s say you’re in /home/username/Documents and want to go
to Photos, a subdirectory of Documents. To do so, enter the following
command:
cd Photos.
If you want to switch to a completely new directory, for
example, /home/username/Movies, you have to enter cd followed by
the directory’s absolute path:
cd /home/username/Movies
Here are some shortcuts to help you navigate:
4. ls command
The ls command lists files and directories within a system. Running it
without a flag or parameter will show the current working directory’s
content.
To see other directories’ content, type ls followed by the desired path.
For example, to view files in the Documents folder, enter:
ls /home/username/Documents
Here are some options you can use with the ls command:
5. cat command
Concatenate, or cat, is one of the most frequently used Linux
commands. It lists, combines, and writes file content to the standard
output. To run the cat command, type cat followed by the file name and
its extension. For instance:
cat filename.txt.
Here are other ways to use the cat command:
6. cp command
Use the cp command to copy files or directories and their content. Take
a look at the following use cases.
To copy one file from the current directory to another, enter cp followed
by the file name and the destination directory. For example:
cp filename.txt /home/username/Documents
To copy files to a directory, enter the file names followed by the
destination directory:
cp filename1.txt filename2.txt filename3.txt
/home/username/Documents
To copy the content of a file to a new file in the same directory,
enter cp followed by the source file and the destination file:
cp filename1.txt filename2.txt
To copy an entire directory, pass the -R flag before typing the source
directory, followed by the destination directory:
cp -R /home/username/Documents
/home/username/Documents_backup
7. mv command
The primary use of the mv command is to move and rename files and
directories. Additionally, it doesn’t produce an output upon execution.
Simply type mv followed by the filename and the destination directory.
For example, you want to move filename.txt to
the /home/username/Documents directory:
mv filename.txt /home/username/Documents.
You can also use the mv command to rename a file:
mv old_filename.txt new_filename.txt
8. mkdir command
Use the mkdir command to create one or multiple directories at once
and set permissions for each of them. The user executing this command
must have the privilege to make a new folder in the parent directory, or
they may receive a permission denied error.
Here’s the basic syntax:
mkdir [option] directory_name
For example, you want to create a directory called Music:
mkdir Music
To make a new directory called Songs inside Music, use this command:
mkdir Music/Songs
The mkdir command accepts many options, such as:
9. rmdir command
To permanently delete an empty directory, use the rmdir command.
Remember that the user running this command should
have sudo privileges in the parent directory.
For example, you want to remove an empty subdirectory
named personal1 and its main folder mydir:
rmdir -p mydir/personal1
10. rm command
The rm command is used to delete files within a directory. Make sure
that the user performing this command has write permissions.
Remember the directory’s location as this will remove the file(s) and you
can’t undo it.
Here’s the general syntax:
rm filename
To remove multiple files, enter the following command:
rm filename1 filename2 filename3
Here are some acceptable options you can add:
15. df command
Use the df command to report the system’s disk space usage, shown in
percentage and kilobyte (KB). Here’s the general syntax:
df [options] [file]
For example, enter the following command if you want to see the current
directory’s system disk space usage in a human-readable format:
df -h
These are some acceptable options to use:
16. du command
If you want to check how much space a file or a directory takes up, use
the du command. You can run this command to identify which part of
the system uses the storage excessively.
Remember, you must specify the directory path when using
the du command. For example, to check /home/user/Documents enter:
du /home/user/Documents
Adding a flag to the du command will modify the operation, such as:
-x extracts a file.
-t lists the content of a file.
-u archives and adds to an existing archive file.
Check out the more practical examples to know more about the other
functions.
38. su command
The switch user or su command allows you to run a program as a
different user. It changes the administrative account in the current log-in
session. This command is especially beneficial for accessing the system
through SSH or using the GUI display manager when the root user is
unavailable.
Here’s the general syntax of the command:
su [options] [username [argument]]
When executed without any option or argument, the su command runs
through root privileges. It will prompt you to authenticate and use
the sudo privileges temporarily.
Here are some acceptable options to use:
40. ps command
The process status or ps command produces a snapshot of all running
processes in your system. The static results are taken from the virtual
files in the /proc file system.
Executing the ps command without an option or argument will list the
running processes in the shell along with: