Skip to content

Instantly share code, notes, and snippets.

@root-ali
Forked from mthri/command-line-hero.MD
Created October 2, 2020 15:55
Show Gist options
  • Save root-ali/2c93f5d1f2bb75d4f71ff34445887332 to your computer and use it in GitHub Desktop.
Save root-ali/2c93f5d1f2bb75d4f71ff34445887332 to your computer and use it in GitHub Desktop.
Command Line Hero (Part Software)

Command Line Hero (Part Software)


echo

Display a line of text/string on standard output or a file.

Syntax

echo [Options] [Strings]

Options:

-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

Learn more


ls

List information about files.

Syntax

ls [Options] [File]

Options:

-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

Learn more


lscpu

Display information about the CPU architecture Learn More


lsusb

List USB devices Learn More


lspci

List all PCI devices Learn More


df

Disk Free - display free disk space.

Syntax

df [Options] [File]

Options:

-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.

Learn more


du

Disk Usage - report the amount of disk space used by the specified files and for each subdirectory.

Syntax

du [Options] [File]

Options:

-s

Display only a total for each argument (summarize).

-h

Human readable

Examples:
du -sh -> Show usage


free

Report system’s memory usage. Learn More


id

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.

Syntax

id [Options] [Username]

Learn more


useradd

Create a new user or update default new user information

Syntax

useradd [Options]

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

Learn more


passwd

Modify a user password.

Syntax

passwd [Options] [Username]

Learn more


usermod

Modify user account information.

Syntax

usermod [Options] [User]

Options:

-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

Learn more


chown

Change owner, change the user and/or group ownership of each given File to a new Owner.

Syntax

chown [Options] [New Owner] [File|Directory]

Options:

-R

Recursively change ownership of directories and their contents.

Learn more


chmod

Change access permissions, change mode.

Syntax

chmod [Options] [u|g][+|-][Permission]

u: User

g: Group

Options:

-R

Change files and directories recursively.

Examples:
chmod u+x File

Learn more


chgrp

Change group ownership.

Syntax

chgrp [Options] [New Group] [File|Directory]

Options:

-R

Recursively change ownership of directories and their contents.

Learn more


ln

Make links between files, by default, it makes hard links; with the -s option, it makes symbolic (or "soft") links.

Syntax

ln [Options] OriginalFile NewLinkFile

Options:

-s

Make symbolic links instead of hard links(soft link).

Learn more


find

Search a folder hierarchy for filename(s) that meet a desired criteria: Name, Size, File Type

Syntax

find [-H] [-L] [-P] [path...] [expression]

Options:

-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 "{}" /;


tail

Output the last part of files, print the last part (10 lines by default) of each FILE;

Syntax

tail [Options] [File]

Options:

-n [k]

Output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth

Learn more


head

Output the first part of files, prints the first part (10 lines by default) of each file.

Syntax

head [Options] [File]

Options:

-n [N]

Output the first N lines.

Learn more


less

Page through text one screenful at a time, Search through output, Edit the command line.

Syntax

less [Options] [File]

ctrl+D -> Page down

ctrl+U -> Page up

/ -> Search

Learn more


grep

Search file(s) for specific text.

Syntax

grep [Options] PATTERN [File]

Options:

-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.

Learn more


cut

Divide a file into several parts (columns)

Syntax

cut [Option] [File]

Options:

-d

Delimiter

-f

Fields

Examples:
cut test.txt -d "," -f 1,2

Learn more


uniq

Report or filter out repeated lines in a file.

Syntax

cut [Option] [File]

Options:

-d

Print only duplicate lines.

-c

Print the number of times each line occurred along with the line.

Learn more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment