Essentials

#Linux

General

echo "TEXT"
Output any text "TEXT" that we provide.

whoami

Find out what user we're currently logged in as.

man man

Shows info about man command and lists all the sections of the manual.

strace objFile

Lists all the system calls used in the program.

ltrace objFile

Lists all the library calls used in the program.

gcc -o objFile source -v

Lists all the path of libraries and headers used in creation of objFile

Network commands

netstat
-t
Lists all the active TCP connections showing domain names.

-u

Lists all the active UDP connections showing domain names.

-n

Lists all the active, showing IP and port numbers.

nslookup domain

Shows the IP address related to the domain (E.g. IP of www.google.it)

dig @server name type

DNS lookup utility:

  • server name or IP address of the name server to query;

  • name name of the resource record that is to be looked up;

  • type type of query is required (ANY, A, MX, SIG, etc.). If no type is specified, A is performed by default.

wc [file]

Prints in order newlines, words, and bytes (characters) counts for file. If file not specified or equal to -, counts from stdin.

route

-n

Show numerical addresses instead of trying to determine symbolic hostnames in routing table.

arp

-a

List all the MAC addresses stored after some ARP requests and replies made by our ethernet interfaces.

ifconfig

List network interfaces.

Directories and files

Listing a directory

ls

-a

List all files, including hidden ones (filename starting with ".")

-color

Colored list [=always/never/auto]

-l

List with long format (show permissions)

-h

List with readable file size

-r

List in reverse order

-R

List recursively directory tree

-s

List file size

-S

Sort by file size

-t

Sort by time & date

-X

Sort by extension name

Search patterns in strings

grep

STRING file

Search STRING in file

-e pattern

Specify pattern

-i

Case insensitive

-v

Invert match (List all string without matches)

-c

Output count of matching lines only

-l

Output matching files only

-n

Precede each matching line with a line number

-b

A historical curiosity: precede each matching line with a block number

-h

Output matching lines without preceding them by file names

-s

Suppress error messages about nonexistent or unreadable files

-w

Force PATTERN to match only whole words

-x

Force PATTERN to match only whole lines

-f file

Take regexes from a file

-o

Output the matched parts of a matching line

Manage files and dir

cd

Take regexes from a file

cp X PATH

Make a copy of file/folder X into the path PATH

mv X PATH

Move/rename the file/folder X in PATH

cat X

Concatenate file content of X

pwd

Print working directory

touch FILE

Create a file with name FILE

rm FILE

Delete a file with name FILE

mkdir DIR

Create a directory with name DIR

rmdir DIR

Delete an empty directory with name DIR

rm -r DIR

Delete recursively a directory with name DIR

Switch between users

su

USERNAME

Switch to USERNAME user by staying in the current folder

-l USERNAME

Switch to USERNAME user by switching to USERNAME home folder

--login USERNAME

Switch to USERNAME user by switching to USERNAME home folder

Process management

Launch a command (symbols for end of command line)

&

If specified at the end of the command, run it in background.

&&

Combine multiple commands together in one line of your terminal.

;

Execute several command in order (one after the other).

Process status

ps

-f

See background processes

-e

More info about processes

-a

Select all processes except both session leaders and processes not associated with a terminal/td>

-u USERLIST

Select by effective user ID (EUID) or name

fg PID

It continues the stopped job with id PID by running it in the foreground

bg

A job control command that resumes suspended jobs (CTRL+Z)

kill PID

It kills the job with id PID

top

It shows all the processes running in Linux working environment

htop

It shows all the processes running in Linux working environment

UNIX common Files

/etc/hosts
Local resolution table.

/etc/services

List all the applications with their port/td>

/etc/protocols

Internet protocols.

/usr/include/x86\_64-linux-gnu/bits/socket.h

List all the protocol type possible for socket.

/usr/include/x86\_64-linux-gnu/sys/socket.h

Definition of struct sockaddr and specific ones.

Shell operators

|
Redirect command output to input of the next command

!!

Previous launched command

<

Redirection of the command input (overwriting text)

>

Redirection of the command output (overwriting text)

>>

Redirection of the of the command output (appending text)

Download files

Command

Description

wget URL

Download to the current folder

wget -O <new_filename> URL

Download with a different name

wget -c URL

Resume download

curl -O URL

Download to the current folder

curl -o <new_filename> URL

Download with a different name

curl -C - -O URL

Resume download

SCP

SFTP

SMB

Then, inside the prompt:

Transfer files

Transfer a file from the SOURCE path to the DEST path, using SSH channel:

SOURCE and DEST have the following format:

or

Automation

  • Open the crontab by running the following command:

A crontab is simply a special file with formatting that is recognised by the cron process to execute each line step-by-step.\ The crontab will execute each line as a cronjob.\

Crontab line fomat

Each line of the crontab has the following format:

MIN
What minute to execute at

HOUR

What hour to execute at

DOM

What day of the month to execute at

MON

What month of the year to execute at

DOW

What day of the week to execute at

cmd

The actual command that will be executed

Special time interval statements

@yearly
Run the task every year at 12:00am on the 1st of January

@annually

@daily

Run the cronjob every day at 12:00am

@midnight

@monthly

Run the job once a month, on the 1st, at 12:00am

@weekly

Run the job once a week at 12:00am on Sunday

@hourly

Run the job at the top of every hour

@reboot

Run the task once, at startup

Open crontab with different user

Time management

Current time

Available timezone

Set new timezone

Last updated