Display a line of text/string on standard output or a file.
echo [Options] [Strings]
-n
Do not output a trailing newline.
Examples:
echo $$
-> Show current process id
echo $?
-> Show last exit code of command
Exit Code | Description |
---|---|
0 | Success |
1 | Error |
126 | Access Denied |
127 | Not Executable |
130 | Process Not Completed (interrupt) |
read more about exit code |
List information about files.
ls [Options] [File]
-a
List all entries including those starting with a dot "." (Even hidden files)
-l
Use a long listing format
-t
Sort by modification time
-r
Reverse order while sorting
-h
Print sizes in human readable format (e.g., 1K 234M 2G)
Examples:
ls -ltrha
Display information about the CPU architecture Learn More
List USB devices Learn More
List all PCI devices Learn More
Disk Free - display free disk space.
df [Options] [File]
-T
Print each filesystem's type.
-h
Append a size letter such as 'M' for megabytes to each size.(human readable)
Examples:
df -Th
-> List free disk space
df -Th /home
-> Show free space of stroge mounted for home direcory.
Disk Usage - report the amount of disk space used by the specified files and for each subdirectory.
du [Options] [File]
-s
Display only a total for each argument (summarize).
-h
Human readable
Examples:
du -sh
-> Show usage
Report system’s memory usage. Learn More
Print real and effective user id (uid) and group id (gid), prints identity information about the given user, or if no user is specified the current process.
id [Options] [Username]
Create a new user or update default new user information
useradd [Options]
-u
The numerical value of the user's ID.
-b
The default base directory for the system if -d HOME_DIR is not specified.
Examples:
useradd amir -u 8585 -b /data
Modify a user password.
passwd [Options] [Username]
Modify user account information.
usermod [Options] [User]
-G
Supplementary groups given by name or number in a comma-separated list with no whitespace.
Examples:
usermod -a -G sudo Ali
-> Append sudo group to user's Ali
Change owner, change the user and/or group ownership of each given File to a new Owner.
chown [Options] [New Owner] [File|Directory]
-R
Recursively change ownership of directories and their contents.
Change access permissions, change mode.
chmod [Options] [u|g][+|-][Permission]
u: User
g: Group
-R
Change files and directories recursively.
Examples:
chmod u+x File
Change group ownership.
chgrp [Options] [New Group] [File|Directory]
-R
Recursively change ownership of directories and their contents.
Make links between files, by default, it makes hard links; with the -s option, it makes symbolic (or "soft") links.
ln [Options] OriginalFile NewLinkFile
-s
Make symbolic links instead of hard links(soft link).
Search a folder hierarchy for filename(s) that meet a desired criteria: Name, Size, File Type
find [-H] [-L] [-P] [path...] [expression]
-name
-iname
Like -name, but the match is case insensitive
-perm
-ctime n
n File's status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.
-size
Examples:
find . -name=*.* | exec ls -l "{}" /;
Output the last part of files, print the last part (10 lines by default) of each FILE;
tail [Options] [File]
-n [k]
Output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth
Output the first part of files, prints the first part (10 lines by default) of each file.
head [Options] [File]
-n [N]
Output the first N lines.
Page through text one screenful at a time, Search through output, Edit the command line.
less [Options] [File]
ctrl+D -> Page down
ctrl+U -> Page up
/ -> Search
Search file(s) for specific text.
grep [Options] PATTERN [File]
-v
Invert the sense of matching, to select non-matching lines(invert match).
-A [NUM]
Print NUM lines of trailing context after matching lines.
-B [NUM]
Print NUM lines of leading context before matching lines.
-C [NUM]
Print NUM lines of output context.
-R
Read all files under each directory, recursively;
-w
Select only those lines containing matches that form whole words.
Divide a file into several parts (columns)
cut [Option] [File]
-d
Delimiter
-f
Fields
Examples:
cut test.txt -d "," -f 1,2
Report or filter out repeated lines in a file.
cut [Option] [File]
-d
Print only duplicate lines.
-c
Print the number of times each line occurred along with the line.