0% found this document useful (0 votes)
4 views10 pages

Linux All Command

The document provides a comprehensive overview of various command-line commands used in Unix/Linux systems, including their syntax and options. It covers commands such as pwd, ls, mkdir, rmdir, cd, touch, cat, rm, cp, mv, head, tail, and more, detailing their functionalities and usage. Additionally, it includes common options for these commands to enhance their functionality and user experience.

Uploaded by

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

Linux All Command

The document provides a comprehensive overview of various command-line commands used in Unix/Linux systems, including their syntax and options. It covers commands such as pwd, ls, mkdir, rmdir, cd, touch, cat, rm, cp, mv, head, tail, and more, detailing their functionalities and usage. Additionally, it includes common options for these commands to enhance their functionality and user experience.

Uploaded by

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

Command

pwd
1 pwd
2 pwd -P or --physical:
3 pwd -L or --logical:
ls Command
1 ls:
2 ls -l:
3 ls -a:
4 ls -h:
5 ls -t:
6 ls -r:
7 ls -S:
8 ls -R:
9 ls -i:
10 ls -F:
11 ls -d:
12 ls -1:
13 ls -G:
14 ls --group-directories-first:
mkdir
1 mkdir directory_name
2 mkdir directory1 directory2 directory3
3 mkdir -p parent_directory/child_directory
4 mkdir -v directory_name
5 mkdir -m mode directory_name
6 mkdir -p parent_directory/child_directory
7 mkdir -i directory_name
rmdir
1 rmdir directory_name
2 rmdir directory1 directory2 directory3
3 rmdir -p parent_directory/child_directory
4 rmdir -i directory_name
5 rmdir -v directory_name
6 rmdir -ignore-fail-on-non-empty directory_name
cd
1 cd directory_name
2 cd

3 cd ..
4 cd /
5 cd -
6 cd -P directory_name

7 cd -L directory_name
touch
1 touch filename

2 touch -t timestamp filename


3 touch file1 file2 file3
4 touch -t timestamp1 file1 -t timestamp2 file2
5 touch -c filename
6 touch -r reference_file filename
cat
1 cat filename
2 cat file1 file2
3 cat file1 >> file2
4 cat -n filename
5 cat -b filename
rm
1 rm example.txt
2 rm file1.txt file2.txt file3.txt
3 rm -r directory_name
cp
1 cp example.txt
2 cp file1.txt file2.txt
3 cp -r directory_name
mv
1 mv example.txt
2 mv old_filename new_filename
3 mv file1.txt file2.txt
4 mv -r directory_name
head
1 head example.txt

2 head -n 5 example.txt
tail
1 tail example.txt

2 tail -n 5 example.txt
more / less
1 more example.txt
2 less example.txt
tac
1 tac example.txt
2 tac file1.txt file2.txt
su
1 su
2 su username
id
1 id
2 id username
cat
1 cat example.txt
2 cat file1.txt file2.txt
3 cat file1.txt file2.txt
cut
1 cut filename
2 cut -d ',' -f 1 file.txt
2 cut -c 1-5 file.txt
4 cut -d ' ' -f 2 --complement file.txt
grep
1 grep example file.txt
2 grep example file1.txt file2.txt
3 grep -r example directory/
comm

1 comm file1.txt file2.txt


sed
1 sed 's/pattern/replacement/' file.txt
2 sed '/pattern/d' file.txt
3 sed -n '/pattern/p' file.txt
4 sed '3i\New line' file.txt # Insert before line 3
sed '3a\New line' file.txt # Append after line 3
5 sed 's/$/ Appended text/' file.txt

sed 's/pattern/replacement/g' file.txt #


Global substitution
6 sed 's/pattern/replacement/2' file.txt #
Substitute on the second occurrence
sed 's/pattern/replacement/i' file.txt #
Case-insensitive substitution

1 tee [OPTION]... [FILE]...


2 command | tee output.txt
3 command | tee file1.txt file2.txt
Use

pwd
Prints the current working directory.
Shows the physical current working directory without symbolic links.
Shows the logical current working directory with symbolic links resolved.
ls Command
Lists files and directories in the current directory.
Long listing format, displays detailed information about files and directories.
Lists all files, including hidden ones (those starting with a dot).
Prints sizes in human-readable format (e.g., 1K, 2M).
Sorts files by modification time, newest first.
Reverses the order of the sort to get reverse alphabetic or oldest first.
Sorts files by size, largest first.
Lists files recursively, i.e., lists files in subdirectories as well.
Prints the inode number of each file.
Appends indicators to entries, indicating their type (e.g., / for directories, * for executables).
Lists only directories.
Prints each file/directory on a new line.
Enables colorized output.
Lists directories first, followed by files.
mkdir
Creates a directory with the specified name.
Multiple Directories: Creates multiple directories at once.
Parent Directories: Creates parent directories if they do not exist.
Verbose Mode: Prints a message for each created directory.
Setting Permissions: Sets permissions for the newly created directory.
Creating Intermediate Directories: Creates intermediate directories as required.
Interactive Mode: Asks for confirmation before creating each directory.
rmdir
Deletes the specified empty directory.
Multiple Directories: Deletes multiple empty directories at once.
Parent Directories: Deletes parent directories if they become empty after removal of the specified directory.
Interactive Mode: Asks for confirmation before removing each directory.
Verbose Mode: Displays a message for each directory removed.
Suppress Error Messages: Does not display error messages if directories are not empty or if they do not exist.
cd
Basic cd: Changes the current directory to the specified directory.
Home Directory: Changes the current directory to the user's home directory.

Parent Directory: Changes the current directory to the parent directory.


Root Directory: Changes the current directory to the root directory.
Previous Directory: Changes the current directory to the previous directory you were in.
Symbolic Links: Resolves symbolic links and changes to the directory they point to.

Logical Path: Uses logical path handling, even when the CDPATH environment variable is set.
touch
Basic touch: Creates a new empty file if it doesn't exist.
Update Timestamp: Updates the access and modification times of an existing file to the current time. If the file doesn't exist, i
creates an empty file.
Specify Timestamp: Sets a specific timestamp for the file. The timestamp format is [[CC]YY]MMDDhhmm[.ss].
Create Multiple Files: Creates multiple files at once.
Create Files with Different Timestamps: Creates files with specified timestamps.
Force Creation: Forces the creation of the file even if it doesn't exist and prevents any error messages.
Reference File Timestamp: Sets the timestamp of one file based on another file's timestamp.
cat
Displaying the contents of a file:
Concatenating multiple files and displaying the output:
Appending the contents of one or more files to another file:
Displaying line numbers along with the contents of a file:
Displaying the contents of a file with line numbers, but only for non-empty lines:
rm
Is used to remove files or directories
To remove multiple files at once, you can specify them separated by spaces:
To remove a directory and its contents recursively, you can use the -r option:
cp
Is used to copy files and directories from one location to another.
To copy multiple files at once, you can specify them separated by spaces:
To copy a directory and its contents recursively, you can use the -r option:
mv
is used to move or rename files and directories
To rename a file, you can use mv by specifying the old file name and the new file name:
To move multiple files at once, you can specify them separated by spaces:
To move a directory and its contents recursively, you can use the -r option:
head
To display the first 10 lines of a file named "example.txt", you would use:
You can also specify the number of lines to display using the -n option. For instance, to display the first 5 lines of "example.txt
would use:
tail
To display the last 10 lines of a file named "example.txt", you would use:
You can also specify the number of lines to display using the -n option. For instance, to display the last 5 lines of "example.txt"
would use:
more / less
To view the contents of a file named "example.txt", you would use:
To view the contents of a file named "example.txt", you would use:
tac
To print the contents of a file named "example.txt" in reverse order, you would use:
You can also specify multiple files, and tac will print the content of each file in reverse order:
su
To switch to the root user account, you would use:
If you want to switch to a different user account, you would specify that user's username after the su command:
id
To display information about the current user, you would simply use:
If you want to display information about a specific user, you would specify that user's username after the id command:
cat
To display the contents of a file named "example.txt", you would use:
To display the contents of multiple files, you can specify them separated by spaces:
Also concatenate the contents of multiple files and redirect the output to another file, effectively merging them:
cut
Is used to extract sections from each line of a file or from the standard input.
Extract the first field from a file where fields are delimited by a comma:
Extract characters 1 through 5 from each line of a file:
Extract the complement of the second field from a file:
grep
Is a powerful utility used for searching text files or the output of other commands for lines that match a specified pattern.
For searching multiple files at once:
To search recursively in a directory and its subdirectories, you can use the -r option:
comm
Is used to compare two sorted files line by line.
To find the lines that are common to both files, you would use:
sed
Substitute text: Replace occurrences of one string with another.
Delete lines: Remove lines matching a specific pattern.
Print specific lines: Print only lines matching a specific pattern.
Insert text: Insert text before or after a specific line.
Append text: Append text to the end of every line.

Substitution with flags: Perform a global substitution with various flags.

is used to read from standard input and write to standard output and files simultaneously.
to save the output of a command to a file named "output.txt" and also display it on the terminal, you would use:
also specify multiple files to save the output to:
Some common options used with the command include:
-r or --recursive: Allows removal of directories and their contents recursively.
-f or --force: Forces the removal of files without prompting for confirmation, even if the file is write-protected.
-i or --interactive: Prompts for confirmation before removing each file.
-v or --verbose: Displays detailed information about the files being removed.
--preserve-root: Prevents the root directory / and its subdirectories from being removed.
--no-preserve-root: Overrides the default behavior of preserving root directory and its subdirectories.
-d or --dir: Removes empty directories.
-I or --ignore-missing: Does not display an error message if a specified file does not exist.
--help: Displays usage information and exits.
--version: Displays version information and exits.
-n, --lines=[-]NUM: Display the first NUM lines of each file. With the '-' sign, it prints all lines except the last NUM lines.
-c, --bytes=[-]NUM: Display the first NUM bytes of each file. With the '-' sign, it prints all bytes except the last NUM byte
-q, --quiet, --silent: Never print headers giving file names.
-d: Display the file name and percentage through the file at the bottom of each page.
-f: Count logical rather than screen lines.
-p: Don't pause at the end of each screenful of text.
+: Start at the specified line number or byte offset within the file.
-N: Display line numbers.
-i: Ignore case in searches.
-F: Quit if the entire file fits on one screen.
-R: Display ANSI color escape sequences.
-b, --before: Attach a header indicating the file name before each file's contents.
-r, --regex: Interpret the separator specified by -s as a regular expression.
-s, --separator=STRING: Use STRING as the separator instead of newline.
-c, --command COMMAND: Pass a single command to execute using the specified user's account.
-l, --login: Simulate a full login session for the specified user, including loading the user's environment variables.
-s, --shell SHELL: Run the specified shell instead of the default shell for the target user.
-u, --user: Display only the user ID.
-g, --group: Display only the primary group ID.
-G, --groups: Display the list of supplementary groups.
-n, --name: Display the name instead of the number for the user or group ID.
-r, --real: Display the real ID instead of the effective ID.
-n, --number: Number all output lines.
-b, --number-nonblank: Number nonempty output lines, overrides -n.
-s, --squeeze-blank: Suppress repeated empty output lines.
-E, --show-ends: Display a dollar sign ($) at the end of each line.
-T, --show-tabs: Display TAB characters as ^I.
-v, --show-nonprinting: Display nonprinting characters as ^ followed by a character code.
-f, --fields=LIST: Specify a list of fields to extract. Fields are separated by a delimiter (by default, a tab) and are numbered sta
-f 1,3 extracts the first and third fields.
-d, --delimiter=DELIM: Specify the delimiter character that separates fields in the input file. By default, the tab character is u
-c, --characters=LIST: Specify a list of character positions to extract. For example, -c 1-5 extracts characters 1 through 5.
--complement: Select the complement of the fields specified by -f. This option is used to select fields not included in the list.
-s, --only-delimited: Suppress lines that do not contain the delimiter character specified by -d. By default, cut prints lines eve
any delimiters.
-i, --ignore-case: Ignore case distinctions in both the pattern and input files.
-v, --invert-match: Invert the sense of matching to select non-matching lines.

-n, --line-number: Prefix each line of output with the line number within its input file.
-l, --files-with-matches: Suppress normal output and display the names of files that contain matching lines.
-c, --count: Suppress normal output and display the count of matching lines for each input file.
-e, --regexp=PATTERN: Use PATTERN as the pattern to search for. This option allows using multiple patterns.
-E, --extended-regexp: Interpret PATTERN as an extended regular expression (ERE) instead of the default basic regular expre
-1: Suppress printing the first column (lines unique to FILE1).
-2: Suppress printing the second column (lines unique to FILE2).
-3: Suppress printing the third column (lines common to both files).
-i: Ignore case distinctions in comparisons.
-u: Suppress printing lines that appear in both files.
IN MORE /
LESS

IN ID

IN CAT

IN CUT

IN GREP
IN GREP

IN COMM

You might also like