Wednesday, November 9, 2022

All Linux Commands

 *MOST USED

ls -List files in directory

ls -a List all files, including hidden ones

pwd -Show the directory currently working in

mkdir- [directory] Create a new directory

rm- [file_name] Remove a file

cd- [directory] Change working directory

mv- [file] [destination] Move file to new

 destination

cp- [file] [destination] Copy file to new destination

grep- [PATTERN] [FILE] Find lines containing [PATTERN] in [FILE]

less [filename]- Display the contents of a file or a command

output one page at a time



*NETWORK DIAGNOSTIC COMMANDS (CONT.)

hostname -Display hostname of computer

hostname –I (capital ‘i’ not lowercase “L”)- Display all IP addresses of computer

ifdown [options] -a|[device] -Shutdown network interface

ifup [options] -a | [device]- Start a network interface

traceroute [host]- Perform traceroute to [host]




*FILE COMMANDS (CONT.)

tar-Stands for for tape archive and is used used

to create archive and extract archived files

tar -cf --Create an archive with a given file name

tar –xvf [file_name]- Unarchive an archive.

x includes the eXtended attributes of the

files (metadata)

v is verbose mode

f tells tar what file/archive you are

unarchiving

-mv [file name] /path/to/new/location - Move a file to a new directory

cat [file1][file2] -Concatenate files and output


-di! [file_name_1] [file_name_2] -File compare, line by line (note: di ! is

-whitespace sensitive)

-echo [text]>>[file_name]- Echo prints arguments to standard output,

-‘>>’ redirects standard output to append to a-

file [file_name]- defines target file name

-locate [file_name]- Locate a file in the file system


curl [options] [URL]- Curl is used for transferring data from or to a

-server without user interaction. Curl is used

to download or upload data using HTTP,

HTTPS, SCP , SFTP , or FTP .

-wget [URL] -Download a file from a server



*FILE COMMANDS

FILE COMMAND

ls List files in directory

ls -a List all files, including hidden ones

pwd Show the directory currently working in

mkdir [directory] Create a new directory

rm [file_name] Remove a file

rm -r [directory_name] Remove a directory and files recursively

rmdir Remove an empty directory

cp [file_name1] [file_name2] Copy the contents of the first file to a new

destination, which can be in a second folder

cp -r [directory_name1]

[directory_name2]

Recursively copy the contents of the first

directory into the second directory

mv [file_name1] [file_name2] Move file_name1 to file_name2

ln -s /path/to/[file_name] [link_name] Create a symbolic link to a file

touch [file_name] Create a new file

head [file_name] Show the first 10 lines of a file

tail [file_name] Show the last 10 lines of a file

gpg -c [file_name] Encrypt a file

gpg [file_name.gpg] Decrypt a file

wc Print the number of words, lines, and bytes in

a file




*NETWORK DIAGNOSTIC COMMANDS


ifconfig/ip -Get the IP address, MAC address, and MTU of

available networks

ping [address] -&Send ICMP ECHO_REQUEST packets to In

network host at [address]

nslookup [address] -Use the IP address to discover a domain

name, or vice versa.

nettop -Monitor network activity, showing a list of

processes and corresponding process IDs

with network connections

netstat Display which ports are active on your

machine, their status, and what they're

connected to

dig [record type] [domain] - Gather information about a particular

domain. Try “dig txt google.com




*SSH (LOGIN)

ssh [IP address] -Connect to a host

ssh user@server -Connect to a server (default port 22)

ssh user@server -p other_port -Use a specific port declared in sshd_config

ssh user@server [command to run] -Run a command on a remote server

ssh-copy-id hostname_or_IP -Copy a unique key pair to server

ssh -i ~/.ssh/specific_ssh_fkey -Specify other ssh key for connection



*PIPES/REDIRECTION

> -Represents output redirection and redirects

output to a file and overwriting the file


>> -Redirects output to a file and appends the

redirected output rather than overwrites

< -Represents input redirection and redirects

the given input file

<< -Launch a file and and captures user input

until EOF

| (ex. command_1 | command_2 |

command_3)

-A Linux pipe is a form of redirection used to

combine two or more commands where the

output of one command acts as the input of

the next command in the sequence.






*SYSTEM INFORMATION


lshw | less -List all hardware and pipes to the less

command for easy reading and pagination

top -Display sorted information about

processes

free -Free shows system information such as

free memory and swap in kibibytes

swapon

 

s -Swap information

dmidecode |


 less -Summarize BIOS information

cat /etc/issue -The cat command shows information

about a given directory, in this cat /ect/

issue.

lspci (or -v for verbose) -Show information about all PCI

lsusb (or -v for verbose) -Show information about all usb devices.

df –m -Display free storage in megabytes

du Return disk usage

du –h [directory] &Return disk usage in a readable file size 

format Eg. 1.1K or 15M 1.5G (-m shows file

in megabytes and -g shows a file in

gigabytes)

sudo systemctl restart [service_name] Restart a service

Eg. sudo systemctl restart apache2

kill [pid] Terminate a process. Use the ‘top’

command to find the pid of a process

pstree Display a tree of running processes

pmap –x PID [pid] Display memory information about a

process

cat /proc/cpuinfo Display detailed information about the

CPU





*USER CONTROLS AND MANAGEMENT USER WARNING: SOME OF

THESE COMMANDS CAN BE DANGEROUS. USE WITH CAUTION. 


useradd [user_name] Create a new user

useradd –r [user_name] -Delete a user

passwd Change your password

chown user:group /path/to/file -Change ownership of a file

chown –R user:group /path/to/directory -Change the ownership of a directory and

files

chmod [permission] [file_name] -Change the permissions of a file

Eg. chmod 777 /path/to/file

quit Logout

w -Display currently logged in users

chroot [path] [command] -Change the root directory of a process

finger [username] -Display information about a user

groups [username] -Display the groups a user belongs to

sudo passwd root Set a new password for the root user,

can be used to circumvent the sudo

command

(sudo) service ssh start Start ssh service

(sudo) service ssh status Check ssh service status

(sudo) service ssh stop Stop ssh service

(sudo) service ssh restart Restart ssh service




*OTHER



history Display prior used commands

[tab] -Autocomplete command you are typing, if

autocomplete has been configured for

your shell session

.

man [command name] -Display the manual or help file for a

command

clear Clear all information from the terminal 

window. Not useful for security.

env -Display environment variables

export [variable_name]=[variable_value] -Create a new environment variable

unset [variable_name] Remove environment variable

at [-V] [-q queue] [-f file] [-mldbv] &TIME Run a command at a specific time

crontab –e Create a new crontab or edit an existing

crontab

date Display current system date and time

iostat List CPU and I/O statistics

alias [new command name]=[command] Create a temporary alias for a command

shutdown Turns a computer o"




#aivel 

#Hacking 

All Linux Commands

 *MOST USED ls -List files in directory ls -a List all files, including hidden ones pwd -Show the directory currently working in mkdir- ...