0% found this document useful (0 votes)
13 views

Mastering Linux - Essential Command Line Basics

The document discusses basic Linux commands like ls, cd, cat, grep, sort, cp, mkdir, rm, chmod, chown, and chgrp. It provides descriptions and examples of how each command works and commonly used options.

Uploaded by

Debasish Rout
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Mastering Linux - Essential Command Line Basics

The document discusses basic Linux commands like ls, cd, cat, grep, sort, cp, mkdir, rm, chmod, chown, and chgrp. It provides descriptions and examples of how each command works and commonly used options.

Uploaded by

Debasish Rout
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Linux Basic Commands

• ls:- The ls command in Linux is used to list files and directories within
a specified directory. It's one of the most commonly used commands
and has several options to customize its output. Here are some of the
basic and commonly used options with ls:

• ls: Simply typing ls without any options will list files and directories in the
current directory.
• ls -l: Lists files and directories in long format, providing detailed
information such as permissions, ownership, size, and timestamps.
• ls -a: Displays all files, including hidden files (those starting with a dot).
• ls -h: Prints file sizes in a human-readable format.
• ls -t: Sorts files by modification time, showing the newest files first.
• ls -r: Lists files in reverse order.
• ls -R: Recursively list subdirectories.
Cd:- The cd command in Linux is used to change directories
within the file system. It allows you to navigate through different
directories and move to a specific directory.
Here's how it works:

cd: Typing cd without any arguments takes you to your home


directory.
•cd [directory]: Moves you into the specified directory. For
example, cd Documents moves you into the "Documents"
directory if it exists within the current directory.
•cd ..: Moves you up one directory level (to the parent directory).
•cd /: Takes you to the root directory.
•cd ~username: Switches to the home directory of the specified
user.
•cd -: Switches to the previous directory you were in.
Cat:- The cat command in Linux has various options that can modify its
behavior. Here are some commonly used options:

cat filename: Displays the content of the specified file on the terminal.
•cat file1 file2: Concatenates and displays the content of multiple files.
•cat > filename: Allows you to create a new file and add content to it from the
terminal.
•cat >> filename: Appends content to an existing file.
Additional options :
-n (or --number): Numbers all the output lines. For example, cat -n file numbers
all lines in the file.
•-b (or --number-nonblank): Numbers non-blank lines. Blank lines won't be
numbered.
•-s (or --squeeze-blank): Squeezes consecutive blank lines into one. It doesn't
remove all blank lines but condenses multiple consecutive blank lines into a
single blank line.
•-E (or --show-ends): Displays a $ character at the end of each line to indicate
the line endings.
•-T (or --show-tabs): Displays ^I where tabs are instead of just showing the tab
spacing.
•-v (or --show-nonprinting): Shows non-printing characters (like control
characters and special characters) in a visible way.
grep:- grep is a powerful command-line tool in Linux used for
searching text patterns within files or command output. It stands for
"Global Regular Expression Print." It allows users to search for specific
strings or patterns and print lines that match those patterns.

grep pattern filename: Searches for a pattern in a file and displays


matching lines.
•command | grep pattern: Filters command output to show lines matching
the pattern.
•grep -i pattern filename: Performs a case-insensitive search.
•grep -r pattern directory: Recursively searches for the pattern in a
directory.
•grep -v pattern filename: Displays lines that don't match the pattern.
•grep -n pattern filename: Shows matching lines with line numbers.
•grep -E pattern filename: Uses extended regular expressions for pattern
sort :- The sort command in Linux is used to sort the lines of text in a file
or standard input and display the result on the standard output (usually the
terminal). It arranges the lines alphabetically or numerically, depending on
the options specified.

• -r: Sort in reverse order (descending).


•-n: Sort numerically.
•-f: Perform a case-insensitive sort.
•-u: Remove duplicate lines.

Pipe (I) :- The pipe command in Linux, denoted by the | symbol, is


used to combine the output of one command and pass it as input to
another command without saving intermediate results to a file.
cp :- The cp command in Linux and Unix-like operating systems is used to
copy files and directories from one location to another.

•-r or -R: Copies directories recursively.


-i: Interactive mode. Asks for confirmation before overwriting existing files.
•-u: Updates the destination file only if the source file is newer.
•-v: Verbose mode. Displays detailed information about the copy operation.

If you want to Copy all files from directory to used


:- {cp * .txt /home/ubuntu}

mkdir:- The mkdir command in Linux and Unix-based operating


systems is used to create directories (folders) within the file system.

•-m: Specifies the permission mode for the directory..


•-p: Creates parent directories if they don't exist.
•-v: Displays a message for each directory created, showing its name.

rm & rmdir:- 1) rmdir is used for delete folders.


2) rm is used for files and folders.
File System Ownership and Permissions

• All files and directories have a individual and a group


ownership.
• All files and directories have read (r), write (w), and
execute (x) permissions assigned as octets to the
individual owner (u), the group (g) owner and all others
(o) that are logged into the system.
• You can change permissions if you are the individual
owner or a member of the group.
• Only root can change ownership.
chmod: To change the access permissions of files and
directories.

chown : To change the owner of files and directories .

chgrp : To change the group ownership of files and directories .

You might also like