Difference between revisions of "User:Cyrusty/Useful Commands"

From Organic Design wiki
(Useful Commands and Info)
Line 1: Line 1:
== Useful Commands and Info ==
+
== LINUX COMMANDS ==
  
 
<source lang="bash">
 
<source lang="bash">
ls-al # lists all in current directory
+
cd # Home directory or changes directory
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
rm -rf FILENAMEHERE # deletes files or directories
+
cd .. # Up a directory and to up 2 directories ../.. and so on
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
chmod +x FILENAME # sets all permissions
+
cd - # Returns you to the directory you previously were in
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
mv /FILE/NAME /NEW/LOCATION # moves files
+
cd / # Changes directory to root
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
mv /FILE/NAME NEWFILENAMEHERE # renames the file
+
ls # Lists the files that are in a directory
 +
</source>
 +
 
 +
 
 +
<source lang="bash">
 +
ls –a # Shows all files/hidden files in a directory
 +
</source>
 +
 
 +
<source lang="bash">
 +
ls –al # Shows all files/hidden files and time/write permissions in a directory
 +
</source>
 +
 
 +
<source lang="bash">
 +
ls -alh # Shows same as above command but shows file sizes in a better readable format
 +
</source>
 +
 
 +
<source lang="bash">
 +
ls -l # Shows the files and write permissions in the directory
 +
</source>
 +
 
 +
<source lang="bash">
 +
ls / # Shows the contents of the root directory
 +
</source>
 +
 
 +
<source lang="bash">
 +
cat <file name. extension> # Prints the contents of a file on the shell
 +
</source>
 +
 
 +
<source lang="bash">
 +
mkdir <Directory Name> # Makes a directory
 +
</source>
 +
 
 +
<source lang="bash">
 +
mkdir -p EXAMPLE/RIGHT/IN/HERE # Makes multiple folders in the directory created
 +
</source>
 +
 
 +
<source lang="bash">
 +
mv /FILE/NAME/OR/DIR /TO/DIR/WANTED # Moves a file to a directory or renames a file
 +
</source>
 +
 
 +
<source lang="bash">
 +
rm <FILE NAME> # Removes a file
 +
</source>
 +
 
 +
<source lang="bash">
 +
rmdir <DIRECTORY> # Removes an empty directory
 +
</source>
 +
 
 +
<source lang="bash">
 +
rm –r # Removes a directory and its contents
 +
</source>
 +
 
 +
<source lang="bash">
 +
rm -rf # Force deletes everything
 +
</source>
 +
 
 +
<source lang="bash">
 +
rm –rf / # Deletes everything under root directory
 +
</source>
 +
 
 +
<source lang="bash">
 +
sudo # Runs command as sudo
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
pwd # prints working directory
+
sudo -i # Changes to root privellages
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
top # shows all running processes
+
sudo su # Gives SUPERUSER privellages
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
kill xxxx # choose the process number to kill the running application
+
man <COMMAND> # Displays how a command can be used and what it does
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
tar xzvf FILENAME # extracts zip files
+
grep # searching, finding, filtering command
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
crontab -e # access boot services
+
top # Shows running processes
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
@reboot<TAB> /DESTINATION/OF/FILE/FILENAME # Run a program when rebooting NOTE!! I have to put this in the crontab -e config
+
htop # Shows more information than top and in more detail
 
</source>
 
</source>
  
 +
<source lang="bash">
 +
ps -A # Shows all running processes
 +
</source>
  
 
<source lang="bash">
 
<source lang="bash">
ifconfig # shows internet config
+
kill PID # Kills process under a certain PID
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
whoami # shows current user
+
kill -9 PID # Force kills a process that wont kill normally
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
ps # shows running processes
+
sudo killall NAME # Kill all processes under the NAME
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
sudo nano etc/default/grub # grub info
+
sudo pkill -u USER # Kills all USER processes
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
sudo update-grub # update after making edits to grub
+
head FILENAME # Prints the first 10 lines
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
alias NAME="SOMECOMMAND HERE" # creates and alias for a command
+
tail FILENAME # Prints the last 10 lines
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
chown -R USER:USER FILE/NAME # change all permission
+
clear # Clears the screen
 
</source>
 
</source>
  
 
<source lang="bash">
 
<source lang="bash">
ln -s /PATH/TO/SOMETHING/REAL /usr/local/bin/NAME # makes a file you choose to run by typing an alias
+
pwd # Print working directory
 
</source>
 
</source>
 +
 +
<source lang="bash">
 +
<file name. extension> # Makes a file in current directory ##unsure of this##
 +
</source>
 +
 +
<source lang="bash">
 +
cal # Shows current calender date (also cal mm/yy)
 +
</source>
 +
 +
<source lang="bash">
 +
whatis # Type a command after to see a brief description of what it does/is
 +
</source>
 +
 +
<source lang="bash">
 +
adduser USERNAME # Create a USER
 +
</source>
 +
 +
<source lang="bash">
 +
adduser USERNAME sudo # Adds USER to the sudo group
 +
</source>
 +
 +
<source lang="bash">
 +
who # Shows current users on the machine and when they logged in
 +
</source>
 +
 +
<source lang="bash">
 +
w # Shows whos logged in, from where, how long and what they're doing
 +
</source>
 +
 +
<source lang="bash">
 +
nano # Edit a text file
 +
</source>
 +
 +
<source lang="bash">
 +
vi # Nano is better...
 +
</source>
 +
 +
<source lang="bash">
 +
vim # Another editor... type vimtutor on commandline to learn more
 +
</source>
 +
 +
<source lang="bash">
 +
sort # Sort lines of text files
 +
</source>
 +
 +
<source lang="bash">
 +
wc # Wordcount a text file
 +
</source>
 +
 +
<source lang="bash">
 +
rig # Random Identity Generator
 +
</source>
 +
 +
<source lang="bash">
 +
apt-cache search # ??
 +
</source>
 +
 +
<source lang="bash">
 +
 +
</source>
 +
 +
<source lang="bash">
 +
 +
</source>
 +
 +
 +
== SYSTEM INFO ==
 +
dmidecode | less # Shows bios information
 +
lscpu # Shows cpu/hardware information
 +
lspci # List all PCI devices
 +
lsusb # List all USB devices
 +
lsblk # List all Hard disks, Cd drives etc
 +
cat /proc/meminfo # Shows memory information
 +
cat /proc/version # Shows current running kernal version
 +
 +
 +
 +
## SHUTDOWN/REBOOT ##
 +
shutdown -r +60 # restarts in 60mins
 +
shutdown -h +60 # shutdown in 60mins
 +
poweroff # shuts system down
 +
reboot # restarts computer
 +
init 6 # same as reboot
 +
 +
 +
 +
## HANDY THINGS TO REMEMBER ##
 +
CTRL r # to search for previously used COMMAND
 +
CTRL p # shows previously used COMMAND
 +
CTRL a # brings you to begin of line
 +
CTRL e # brings to the end of line
 +
tail -f FILENAME # this will follow the file while it's being edited
 +
echo "some kind of text" > example.text # this will overwrite the .text file with the quoted line
 +
echo "new line of text" >> example.text # this will write the quoted line on a new line
 +
alias COMMANDNAME="DESIREDNAME" # this will temporarily save a command to the desired name
 +
echo "alias COMMANDNAME=\"DESIREDNAME\";" >> ~/.bashrc # this will permanently save a desired command to the bash file
 +
&& # chain commands together
 +
 +
 +
 +
## NETWORKING ##
 +
ifconfig # Shows network info IP/MAC address
 +
sudo netdiscover # Shows who's on the network and identifies the ip address of each connection
 +
sudo lsof -i # Lists the open ports and the process that owns them (to see which process is bound to port use :PORTNUMBER)
 +
sudo netstat # Seeing what might be exposed to the network
 +
sudo netstat -tulpn # t=tcp, u=udp ports, l=listening ports, p=processes, n=numerical
 +
sudo macchanger -s enp4s0/eth0/wps/ # To see mac addresses
 +
sudo macchanger -r enp4s0 # Changes the current mac address to a new one
 +
 +
ssh -NCD 1080 user@ip # Proxy network traffic over port 1080 (edit below settings on firefox to port traffic correctly)
 +
Manual Proxy Configuration
 +
Socks Host: localhost
 +
port: 1080
 +
 +
 +
 +
## EXAMPLES OF THINGS ##
 +
ls -alh /home/user/some/random/place >> ANYNAME # cat ANYNAME to see it show the directory with info
 +
grep WHATEVERSEARCHINGFOR ./* # Useful for findings things.. If successful this will print out what it finds in the shell
 +
 +
 +
## SSH ##
 +
ssh-keygen -t # creates a key in .ssh
 +
sudo nano /etc/ssh/sshd_config # change ssh parameters (key logging/password authentication)
 +
sudo service ssh restart # saves ssh modifications
 +
ssh-copy-id USER@IP # saves the pub key to be known as an authenticated key
 +
scp -r USER@IP /home/USER/FILE/FOLDER /home/local/machine # copy from server to localmachine
 +
scp -r /home/USER/local/machine/file/folder USER@IP:/home/USER/VPS
 +
 +
 +
 +
## RANDOM PASSWORD GENERATORS ##
 +
openssl rand -base64 32 # generates random 32 character password
 +
</dev/urandom tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | head -c 10 ; echo # Sauls random character/symbol generated password command
 +
 +
 +
 +
## SYSTEM COMMANDS/SERVICES ##
 +
sudo apt-get update && sudo apt-get install # Updates n upgrades system to latest
 +
crontab -e # the crontab (short for "cron table") is a list of commands that are scheduled to run at regular time intervals on your computer system
 +
sudo nano /etc/default/grub # change grub options (boot timer)
 +
 +
 +
 +
 +
## CRONTAB SCRIPT COMMANDS ##
 +
@reboot macchanger -r enp4s0 # (or eth0) # changes to random mac address on each reboot
 +
 +
 +
 +
## MAIL ##
 +
mail # Checks mail for current user
 +
mail -s "SUBJECT" USER < /home/USER/test.text # sends a mail to the user with test.text as the body
 +
mail -f USER # Checks mail for selected user
 +
mail -f guest # checks guest messages
 +
 +
 +
## PIPING & REDIRECTION ##
 +
cat /FILE/IN/A/DIRECTORY | less # Shows in a opened document view without clogging the terminal
 +
cat /FILE/IN/A/DIRECTORY | espeak # Speaks the text document in linux voice
 +
 +
 +
 +
## FILE PERMISSIONS ##
 +
(R)ead=4
 +
(W)rite=2
 +
(X)ecute=1
 +
d=directory
 +
l=link
 +
4+2+1 = (r+w+x) = 7
 +
4+2 = (r+w) = 6
 +
4+1 = (r+x) = 5
 +
4 = (r) = 4
 +
2+1 = (w+x) = 3
 +
2 = (w) = 2
 +
1 = (x) = 1
 +
 +
chmod xxx dir # Change all files in a single directories permissions
 +
chmod -R xxx dir # Change all file/folders permissions recursively
 +
chown owner:group DIRECTORYNAME # Changes the owner and group name of files
 +
 +
 +
 +
## ACCOUNT MANAGEMENT ##
 +
useradd # Adds a user
 +
useradd -m -d # Create a new user and makes a home directory for the user and define the home directory /home/DIR/FOR/USER
 +
userdel # Deletes a user
 +
usermod -L USER # Locks the user from logging in
 +
usermod -U USER # Unlocks the user so they can log in again
 +
tail /etc/shadow
 +
tail /etc/passwd
 +
tail /etc/group
 +
#Note users will have a "!" after their name if they are locked out of their account
 +
to check this type in the following command "tail /etc/shadow"
 +
 +
 +
## GIT ##
 +
git add . # add all files for committing
 +
git commit -am "COMMIT MESSAGE" # commit the changes locally
 +
git push origin master # push changes to the server

Revision as of 21:37, 23 August 2018

LINUX COMMANDS

cd # Home directory or changes directory
cd .. # Up a directory and to up 2 directories ../.. and so on
cd - # Returns you to the directory you previously were in
cd / # Changes directory to root
ls # Lists the files that are in a directory


ls –a # Shows all files/hidden files in a directory
ls –al # Shows all files/hidden files and time/write permissions in a directory
ls -alh # Shows same as above command but shows file sizes in a better readable format
ls -l # Shows the files and write permissions in the directory
ls / # Shows the contents of the root directory
cat <file name. extension> # Prints the contents of a file on the shell
mkdir <Directory Name> # Makes a directory
mkdir -p EXAMPLE/RIGHT/IN/HERE # Makes multiple folders in the directory created
mv /FILE/NAME/OR/DIR /TO/DIR/WANTED # Moves a file to a directory or renames a file
rm <FILE NAME> # Removes a file
rmdir <DIRECTORY> # Removes an empty directory
rm –r # Removes a directory and its contents
rm -rf # Force deletes everything
rm –rf / # Deletes everything under root directory
sudo # Runs command as sudo
sudo -i # Changes to root privellages
sudo su # Gives SUPERUSER privellages
man <COMMAND> # Displays how a command can be used and what it does
grep # searching, finding, filtering command
top # Shows running processes
htop # Shows more information than top and in more detail
ps -A # Shows all running processes
kill PID # Kills process under a certain PID
kill -9 PID # Force kills a process that wont kill normally
sudo killall NAME # Kill all processes under the NAME
sudo pkill -u USER # Kills all USER processes
head FILENAME # Prints the first 10 lines
tail FILENAME # Prints the last 10 lines
clear # Clears the screen
pwd # Print working directory
<file name. extension> # Makes a file in current directory ##unsure of this##
cal # Shows current calender date (also cal mm/yy)
whatis # Type a command after to see a brief description of what it does/is
adduser USERNAME # Create a USER
adduser USERNAME sudo # Adds USER to the sudo group
who # Shows current users on the machine and when they logged in
w # Shows whos logged in, from where, how long and what they're doing
nano # Edit a text file
vi # Nano is better...
vim # Another editor... type vimtutor on commandline to learn more
sort # Sort lines of text files
wc # Wordcount a text file
rig # Random Identity Generator
apt-cache search # ??


SYSTEM INFO

dmidecode | less # Shows bios information lscpu # Shows cpu/hardware information lspci # List all PCI devices lsusb # List all USB devices lsblk # List all Hard disks, Cd drives etc cat /proc/meminfo # Shows memory information cat /proc/version # Shows current running kernal version


    1. SHUTDOWN/REBOOT ##

shutdown -r +60 # restarts in 60mins shutdown -h +60 # shutdown in 60mins poweroff # shuts system down reboot # restarts computer init 6 # same as reboot


    1. HANDY THINGS TO REMEMBER ##

CTRL r # to search for previously used COMMAND CTRL p # shows previously used COMMAND CTRL a # brings you to begin of line CTRL e # brings to the end of line tail -f FILENAME # this will follow the file while it's being edited echo "some kind of text" > example.text # this will overwrite the .text file with the quoted line echo "new line of text" >> example.text # this will write the quoted line on a new line alias COMMANDNAME="DESIREDNAME" # this will temporarily save a command to the desired name echo "alias COMMANDNAME=\"DESIREDNAME\";" >> ~/.bashrc # this will permanently save a desired command to the bash file && # chain commands together


    1. NETWORKING ##

ifconfig # Shows network info IP/MAC address sudo netdiscover # Shows who's on the network and identifies the ip address of each connection sudo lsof -i # Lists the open ports and the process that owns them (to see which process is bound to port use :PORTNUMBER) sudo netstat # Seeing what might be exposed to the network sudo netstat -tulpn # t=tcp, u=udp ports, l=listening ports, p=processes, n=numerical sudo macchanger -s enp4s0/eth0/wps/ # To see mac addresses sudo macchanger -r enp4s0 # Changes the current mac address to a new one

ssh -NCD 1080 user@ip # Proxy network traffic over port 1080 (edit below settings on firefox to port traffic correctly) Manual Proxy Configuration Socks Host: localhost port: 1080


    1. EXAMPLES OF THINGS ##

ls -alh /home/user/some/random/place >> ANYNAME # cat ANYNAME to see it show the directory with info grep WHATEVERSEARCHINGFOR ./* # Useful for findings things.. If successful this will print out what it finds in the shell


    1. SSH ##

ssh-keygen -t # creates a key in .ssh sudo nano /etc/ssh/sshd_config # change ssh parameters (key logging/password authentication) sudo service ssh restart # saves ssh modifications ssh-copy-id USER@IP # saves the pub key to be known as an authenticated key scp -r USER@IP /home/USER/FILE/FOLDER /home/local/machine # copy from server to localmachine scp -r /home/USER/local/machine/file/folder USER@IP:/home/USER/VPS


    1. RANDOM PASSWORD GENERATORS ##

openssl rand -base64 32 # generates random 32 character password </dev/urandom tr -dc 'A-Za-z0-9!"#$%&'\()*+,-./:;<=>?@[\]^_`{|}~' | head -c 10 ; echo # Sauls random character/symbol generated password command


    1. SYSTEM COMMANDS/SERVICES ##

sudo apt-get update && sudo apt-get install # Updates n upgrades system to latest crontab -e # the crontab (short for "cron table") is a list of commands that are scheduled to run at regular time intervals on your computer system sudo nano /etc/default/grub # change grub options (boot timer)



    1. CRONTAB SCRIPT COMMANDS ##

@reboot macchanger -r enp4s0 # (or eth0) # changes to random mac address on each reboot


    1. MAIL ##

mail # Checks mail for current user mail -s "SUBJECT" USER < /home/USER/test.text # sends a mail to the user with test.text as the body mail -f USER # Checks mail for selected user mail -f guest # checks guest messages


    1. PIPING & REDIRECTION ##

cat /FILE/IN/A/DIRECTORY | less # Shows in a opened document view without clogging the terminal cat /FILE/IN/A/DIRECTORY | espeak # Speaks the text document in linux voice


    1. FILE PERMISSIONS ##

(R)ead=4 (W)rite=2 (X)ecute=1 d=directory l=link 4+2+1 = (r+w+x) = 7 4+2 = (r+w) = 6 4+1 = (r+x) = 5 4 = (r) = 4 2+1 = (w+x) = 3 2 = (w) = 2 1 = (x) = 1

chmod xxx dir # Change all files in a single directories permissions chmod -R xxx dir # Change all file/folders permissions recursively chown owner:group DIRECTORYNAME # Changes the owner and group name of files


    1. ACCOUNT MANAGEMENT ##

useradd # Adds a user useradd -m -d # Create a new user and makes a home directory for the user and define the home directory /home/DIR/FOR/USER userdel # Deletes a user usermod -L USER # Locks the user from logging in usermod -U USER # Unlocks the user so they can log in again tail /etc/shadow tail /etc/passwd tail /etc/group

  1. Note users will have a "!" after their name if they are locked out of their account

to check this type in the following command "tail /etc/shadow"


    1. GIT ##

git add . # add all files for committing git commit -am "COMMIT MESSAGE" # commit the changes locally git push origin master # push changes to the server