Linux Regular Use Command

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

Linux Commands

1. Creating an archive using tar command


Creating an uncompressed tar archive using option cvf
This is the basic command to create a tar archive.
Syntax:
tar cvf archive_name.tar dirname
tar cvzf archive_name.tar.gz dirname
In the above command:
c – create a new archive
v – verbosely list files which are processed.
f – following is the archive file name
z – filter the archive through gzip
Linux Commands
2. Extracting (untar) an archive using tar command
Extract a *.tar file using option xvf
Extract a tar file using option x as shown below:
Syntax:
tar xvf archive_name.tar
tar xvzf archive_name.tar.gz
In the above command:
x – extract files from archive
v – verbosely list files which are processed.
f – following is the archive file name
z – filter the archive through gzip
Linux Commands
3. Find command
i. Find Files Using Name
This is a basic usage of the find command. This example finds all
files with name — MyCProgram.c in the current directory and all its
sub-directories.
Syntax:
find -name “filename"
Ex:
find -name "MyCProgram.c“
ii. Find Files Using Name and Ignoring Case
Syntax:
find -iname “filename“
Ex
find -iname "MyCProgram.c"
5. grep command
The grep command is one of the most useful commands on Linux. It is
an acronym, and its full form is; global regular expression print.’ The
sheer adequacy makes it a frequently used command on Linux. The grep
command looks for lines and prints the ones that match a predefined
search pattern.
Syntax:
grep [options] pattern [files]
Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line, with each such part
on a separate output line.
i. Search for the given string in a single file
grep "search_string" filename
ii. Case insensitive search
The -i option enables to search for a string case insensitively in the give
file. It matches the words like “HELLO”, “Hello”, “hello”
Ex:
grep -i “HEllo" filename
iii. Displaying the count of number of matches
We can find the number of lines that matches the given string/pattern
grep -c “Hello" geekfile.txt
iv. Show line number while displaying the output using grep -n : To
show the line number of file with the line matched.
Ex:
grep -n “hello" filename
v. Inverting the pattern match : You can display the lines that are not
matched with the specified search sting pattern using the -v option.
Ex:
grep -v “hello" filename
vi. Search a string Recursively in all Directories
If you would like to search for a string in the current directory along with
all of the subdirectories, you can specify the –r option to search recursively:
grep –r “hello” *
Vii together multiple options
grep –inr “hello” *
grep –nr “hello” *
grep –ir “hello” *
Linux Commands
6. Diff command
This is the traditional way to find out the difference two files is
using diff command.
Syntax:
diff empfile1.txt empfile2.txt
7. vimdiff command
This is the traditional way to find out the difference two files is
using vimdiff command.
Syntax:
vimdiff empfile1.txt empfile2.txt
Linux Commands
8.alias:
It is used to create the user defined command
Syntax:
alias alias_name=command
Ex:
alias cl=clear
9. cat Command:
The cat command is simple, and one of the most frequently used commands that
are used in a variety of ways. It is short for ‘concatenate’ and permits users to create
files, redirect output, list the contents of a file, and even concatenate multiple files.
Syntax:
cat file1 file2……………filen
Ex:
The command cat is convenient and allows the user to accomplish many tasks with a
single expression. For example, to view the content of the /abc/passwd file from the
home directory, type the below command:
cat /etc/passwd
Next, type the following to view the contents of multiple files, in this case:
cat /etc/passwd file2
 
Now in case the content of a file is long and does not fit the terminal, then the user
can use the following parameters:
cat test.txt | more
Now, if a user wants to see less, a user can go back by typing the below parameter:
cat test.txt | less
10. df Command:
The df is a fundamental command on Linux. Using df, coders can
display the size, available space, and used space on the filesystems of
the device. It comes with multiple options, such as the following:
Syntax:
df sub_options
Ex:
It shows human-readable: print sizes in power of 1024, which is Mb or
Gb,all kind file systems
df -h
It shows human-readable: print sizes in power of 1024, which is Mb or
Gb,all kind of used file systems
 
df –h foldername
11.du command:
The du command is a command line utility for reporting file system disk
space usage. It can be used to find out disk usage for files and folders and to
show what is taking up space. It supports showing just directories or all files,
showing a grand total, outputting in human readable format and can be
combined with other UNIX tools to output a sorted list of the largest files of
folders on a system.
Syntax:
du sub_options file/folder_names
Ex:
To view disk usage in human readable format pass the -h option
du –h Hakeem
To view the file size of a directory pass the -s option to the du command
followed by the folder. This will print a grand total size for the folder to
standard output.
du -s Hakeem
Along with the -h option a human readable format is possible.
du –sh Hakeem
11.lsblk command:
lsblk is used to display details about block devices and these block
devices(Except ram disk) are basically those files that represent devices
connected to the pc.
Syntax:
1.To display block size
$ lsblk
2.To display empty block devices as well.
$ lsblk –a
3.To display file system block devices as well.
$ lsblk –f
4. To print information about device owner, group, and mode of block
$ lsblk -m
12.free command:
The free command-line utility provides users with a summary of the
total available free space on the computer. More so, it also displays the
total amount of used memory of the Random Access Memory (RAM)
and the swap memory on the computer. Using the free command will
also present the buffers leveraged by the kernel.
Syntax:
free
Ex:
To view disk usage in human readable format pass the -h option
free –h
13.uname command:
The uname command provides users with the system information of the
Linux system or computer they are using. It comes with several options
that enable users to view all or specific information they want. Below is
the option programmers can use with the uname command:
Syntax:
uname options
Ex:
uname -a
-a = you can use this option to see everything
-s = with this option users can view the kernel information
-v = the option allows one to see the kernel version of the system
-r = the parameter lets one view the kernel release
14.echo command:
The echo command is leveraged to print a string of text passed as an
argument to the terminal window. It comes as the built-in command and
is frequently used get output status text in shell scripts.
Syntax:
echo argument
Ex:
1. echo “Hello World”
2. echo $HOME
3. echo $PATH
4. echo $USER
15.ps Command
The ps command displays a process that is currently running on the Linux machine. It
provides a real-time display of all active processes. The ps command provides a basic
summary of the process that includes its Process ID. In many operating systems, the process
is referred to as tasks. By default, the ps command will list active operations in the current
shell. However, you can use options to change to different shells.
Syntax:
ps sub_options
Ex:
1.ps ->it will display current active process
In case, a user wants to view the process of a specific user then they can add -u(user) option
to the ps command.
ii.ps –u user_name
ps –u hakeem
In case, a user wants to view the process of a specific user then they can add -u(user) option
to the ps command.
ps –e ,ps -ef
for less
ps -e |less ,ps –ef|less
for more
ps -e | more , ps –ef|more
16. kill command examples
Use kill command to terminate a process. First get the process id using
ps -ef command, then use kill -9 to kill the running Linux process as
shown below. You can also use killall, pkill, xkill to terminate a unix
process.
Syntax:
kill -9 process_ID
Ex:
kill -9 1234
Ex1:
ps -ef | grep application_name
ps –ef |grep vim
kill -9 vim_process_id
killall -9 application_name
17.date command
Date command is used to display the current date and time, to set the
time
i.date
ii.date –s “m/d/year h:mi:se”
ex:
date –s “01/03/2020 07:44:32”
18.touch command
It is used to create a file without any content. The file created using
touch command is empty. This command can be used when the user
doesn’t have data to store at the time of file creation.
Syntax:
touch file_name
To create a multiple files
Syntax:
touch File1_name File2_name File3_name
18.man command
man command in Linux is used to display the user manual of any
command that we can run on the terminal. It provides a detailed view
of the command which includes NAME, SYNOPSIS, DESCRIPTION,
OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS,
EXAMPLES, AUTHORS and SEE ALSO.
Syntax:
man [COMMAND NAME]...
man [OPTION]... [COMMAND NAME]...
Ex:
man printf
man 2 intro
-w option: This option returns the location in which the manual page
of a given command is present.
man -w ls
19. whoami command
The whoami command is simple and mostly comes handy for amateur
Linux users. It tells the user with a username they are logged in as
Syntax:
whoami
20. whereis command
When you want to find out where a specific Unix command exists (for
example, where does ls command exists?), you can execute the
following command.
Syntax:
whereis ls
21. whatis  command
Whatis command displays a single line description about a command
Syntax:
whatis ls
22.tail command
The tail command is a command-line utility that lists the last lines of a
file that are given via standard input. Programmers can use tail even to
track files in real-time. It means that a user can view new lines as they
are being written. Let’s look at the tail command as it is in default
Syntax:
Print the last 10 lines of a file by default.
tail filename.txt
Print N number of lines from the file named filename.txt
tail -n N filename.txt
Ex:
tail -n 5 filename.txt
view the content of the file in real time using tail –f
tail -f log-file
23.history command
The history command is a way to view the commands that a user has
inputted previously on the command line. The default limit is set to
display only the latest five hundred commands. It is an easy way to
repeat the commands just by inputting ! (exclamation) the point with
the number of the command that the user wants to repeat from the list.

Syntax:
history
24.ls command
The ‘ls’ is the most basic and probably one of the first commands anyone learns.
It is a simple command to list the directory of files and directories. The ls
command will list files in the active directory if the user does not specify other. It
is one of the most frequently used commands as users can concatenate its
various options.
Syntax:
ls
The above command will list all files in the current directory. For a
comprehensive list, coders have to use the -l(long) option and use the -
h(human) option to ensure the file sizes are mentioned in a human-readable
format.
ls –lh
In case, a user also wants to view hidden files, then enter -a (all files) parameter:
ls –lha
To modify the list in order of latest updates, enter the following command:
ls -lt
25.shutdown command
The shutdown command is simple as it sounds and most users will come across as
soon as they learn about Linux commands. As the name sounds, the shutdown
command will switch off or shut down your Linux system.
There are various parameters you can use with the shutdown command, but if no
parameter is specified, then the computer will shut down in one minute.
Syntax:
shutdown
In case you are in a rush and wants to shut down the computer immediately, then use
the ‘now
shutdown now
Users can even schedule shutdown and also notify all users for the same with a single
command. The only thing users are to provide is the time and the pc will shutdown as
per scheduled. You can also schedule in minutes, such as 10 minutes from now. Below
are both examples:
shutdown tonight at 22:00, don’t forget to save your work and enjoy the
weekend!
shutdown +10
Use the -c(cancel) option to cancel the scheduled shutdown.
shutdown -c
26.passwd command
With the passwd command, users can change the password for a user.
It not only lets you change your password but also of other users. The
passwd command is also one of the most frequently used Linux
commands. The command comes in very handy as it makes it very easy
to change the password for anyone in the team. To change others
password, users have to use sudo command as it requires permission
privileges. Type passwd to change your own password
Syntax:
passwd
To change others password, type the following:
sudo passwd max
27. chmod command
The chmod command allows users to alter or assign file permissions flags on a file
or folder. The permission defines who can read, write, or run the file. The code
comes with references, which indicates to whom the permission will be applicable.
Specific letters represent the references, and programmers can use these letters to
assign permission. Below is the list of letters:
u - the owner of the file
g - this represents a group. So when assigned, it will apply to all members of
the file’s group.
o - users who are not the owner or a group member
a - those who are all of the above
Then comes the ‘modes’ that represent each of the permission types. The
following are the permissions that a user can assign for a file:
r - the letter means the user has the permission to the only read
w - the letter corresponds to write or delete the file
x - the mode allows users to execute a file
Users can view permissions of all files using the -l command. It will list file in the
current directory. It will result in a string of characters as follows:
So, one can use chmod to give change or assign permission to either an
owner, group, or others. More so, the string of characters is followed
by digits which represent the specific type of file permission.
0: No permission is assigned
1: Execute permission
2: it has to write permission
3: the user has write and execute permissions
4: users can only read with this permission
5: users have read and permission to execute
6: it indicates that you have both read and write permissions
7: it offers you to do anything with the file such as read, write and
execute

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy