linux commands.pdf

1,457 views 7 slides Jan 11, 2024
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

linux


Slide Content

Simple commands in Linux:

1. Is – Displays information about files in the current directory.
Syntax of `ls` command in Linux
ls [option] [file/directory]

2. pwd – Displays the current working directory.
pwd [OPTIONS]

3. mkdir – Creates a directory.
Syntax:
mkdir [options...] [directories ...]
Options available in mkdir
1) –help:
It displays help-related information and exits.
Syntax:
mkdir --help

2) –version:
It displays the version number, some information regarding the license and exits.
Syntax:
mkdir –version

3)-p:
A flag which enables the command to create parent directories as necessary. If the
directories exist, no error is specified.
Syntax:
mkdir -p [directories]

4) -m:
This option is used to set the file modes, i.e. permissions, etc. for the created
directories. The syntax of the mode is the same as the chmod command.
Syntax:
mkdir -m a=rwx [directories]



4. cd – To navigate between different folders.
Syntax:
cd [directory_name]
Here, replace [directory_name] with the desired directory you want to move in.

For Example:
If we want to move to a subdirectory name “Documents”
cd Documents



5. rmdir – Removes empty directories from the directory lists.
Syntax- rmdir <directory>

6. cp – Moves files from one directory to another.
Syntax:
cp [OPTION] Source Destination
cp [OPTION] Source Directory
cp [OPTION] Source-1 Source-2 Source-3 Source-n Directory

Example:
$ ls
a.txt

$ cp a.txt b.txt

$ ls
a.txt b.txt

7. mv – Rename and Replace the files

Syntax:
mv [options(s)] [source_file_name(s)] [Destination_file_name]

8. rm – Delete files
Syntax:
rm [OPTION]... FILE...
Ex:
Removing one file at a time
$ rm a.txt

$ ls
b.txt c.txt d.txt e.txt

Removing more than one file at a time
$ rm b.txt c.txt

$ ls
d.txt e.txt

9. touch – Create empty files
Syntax:
touch file_name


10. cat – Display file contents on terminal
Syntax:
cat file_name

11. echo- Echo is a command used for displaying lines of text or string which are
passed as arguments on the command line
Syntax:
echo [string]
Example:
echo "MCA Class 1st"

12. clear – Clear terminal
Syntax:
reset

Practicals
1.ls Command with different argument
ls is a Linux shell command that lists directory contents of files and directories.
It provides valuable information about files, directories, and their attributes.
Syntax of `ls` command in Linux
ls [option] [file/directory]

Commonly Used Options in `ls` command in Linux

Options Description
-l
known as a long format that displays detailed information about files and
directories.
-a Represent all files Include hidden files and directories in the listing.
-t
Sort files and directories by their last modification time, displaying the
most recently modified ones first.
-r
known as reverse order which is used to reverse the default order of
listing.
-S Sort files and directories by their sizes, listing the largest ones first.
-R List files and directories recursively, including subdirectories.
-i
known as inode which displays the index number (inode) of each file and
directory.

Options Description
-g
known as group which displays the group ownership of files and
directories instead of the owner.
-h Print file sizes in human-readable format (e.g., 1K, 234M, 2G).
-d List directories themselves, rather than their contents.

2. File contained in home directory
There are multiple ways to access and return to the home directory. Some commands are very
helpful for the directories such as cd, pwd, mkdir, pwd, ls, and rmdir.

Here, we can explore our home directory.
Generally, our terminal opens with the user's particular directory. To change directory to
home directory, execute the cd command as follows:
1.cd /home
The above command will change the directory to home. To list the home directory,
execute the ls command as follows:
ls

We can get back to our home directory by executing the cd command without any
argument. It will back to our home directory from any directory we are working on.
Execute it as follows:
cd
2. pwd
To display the current working directory, execute the pwd command as follows:
pwd

3. mkdir
To create a directory under a directory, execute the mkdir command as follows:
mkdir <directory name>


3. Move the file from one directory to another
The mv command moves files and directories from one directory to another, or renames
a file or directory. If you move a file or directory to a new directory, it retains the base file
name. When you move a file .
Syntax:
mv [options(s)] [source_file_name(s)] [Destination_file_name]
4. The command to sort the directory to listing by the size
To sort files by size, use the option -S with the ls command. Mind it, it's capital S for
sorting. That's good but you can make it better by adding the -h option. This option
makes the output of the ls command displays the file size in human readable formats.

The -S option of the ls command sorts the files by size.

5. To print the current working directory

Print Current DirectoryTo know your current directory, you can use
the pwd command which stands for Print Working Directory.
Syntax of `pwd` command in Linux
pwd [OPTIONS]
This command doesn’t have any arguments or options, but it can accept flags for
specific behavior.

Flags For Specific behavior in `pwd` command in Linux.
 The “-L” flag resolves symbolic links and prints the path of the target directory.
 The default behavior of the shell built-in “pwd” is equivalent to using “pwd -L”.
 Mention the “-P” flag, which displays the actual path without resolving symbolic
links.
 The default behavior of the binary “/bin/pwd” is the same as using “pwd -P”
Tags