| uname -acat /etc/*-release
|
Update software -y assumes yes to all prompts
| |
Install software (Debian/Ubuntu) -y assumes yes to all prompts
| sudo apt-get install -y <PACKAGE_NAME>
|
| sudo apt-get --purge remove <PACKAGE_NAME>
|
| |
Show all files in current directory -F show all directories with a / at the end, making them easier to see
-h show directory sizes in human readable format
-R list directories recursively
-t sort by modification date in ascending order, means the higher will be come first
-i displays Inode information
-o shows owner of the files and directories but not the groups
*<STRING_TO_MATCH>* used to only display files and directories matching the string
This doesn't see to work correctly when used with -a
| ls -l
ls -l *<STRING_TO_MATCH>*
|
| |
Create hard and soft links to files | ln <FILE1> <FILE2>
ln -s <FILE1> <FILE2>
|
| |
Create, update the access, change, and modify times of files -t allows you to set the date and timestamp of the file to a specific value e.g. 12091600
| touch
touch -t <DATE> <FILENAME>
|
Create and remove directories -rf Forcefully remove a directory that contains files recursively
| mkdir <NEW_DIRECTORY>
rmdir <DIRECTORY_TO_DELETE>
|
Moving or Renaming a file Move a file to another location, while possibly changing its name at the same time.
| |
Removing a file -f forcefully remove a file
-r interactively remove a file (ask before removing)
| |
Viewing files (or combine files) that are not very long It does not provide any scroll-back. View backwards, starting at the last line with tac
| |
| |
Restrict file so only owner can read -R to recursively change permissions for all folders and files below
| chmod 440 <FILE/FOLDER>
chmod -R 400 <FILE/FOLDER>
|
| |
Count words in a file Default: lines, words, characters/bytes? -l Print the number of lines.
-w Print the number of words.
-m Print the number of characters.
-c Print the number of bytes.
-L Print the length of the longest line
| |
View larger files with a paging program It pauses at each screen full of text, provides scroll-back capabilities, and lets you search and navigate within the file. Use / to search for a pattern in the forward direction and ? for a pattern in the backward direction. An older program named more is still used, but has fewer capabilities: "less is more".
| |
Show the first few lines of a file | |
Shows the last few lines of a file Print the last 10 lines of a file by default Change the number of lines by doing -n 15 or just -15 if you wanted to look at the last 15 lines instead of the default.
| |
Used to view documentation | |
Find where a program resides on the filesystem If a program isn't found with which then try whereis as it looks at a broader range of locations
| |
Show home directory path for current user | |
Change directory cd ~ or just cd changes to Home directory
cd .. changes to parent directory (..)
cd - changes to previous directory (- (minus))
| |
Move to a new directory but save the current directory for quick return pushd moves you to the directory specified in the argument
popd returns you to the most recent directory from the last pushd command (so similar to cd - but saves it, even if you go to multiple cd commands between)
dirs displays the current list of all directories saved with pushd
| pushd <NEW_DIRECTORY>
popd
dirs
|
Find a file that contains specific text -w stands for match the whole word
-l (lower-case L) can be added to just give the file name of matching files
-e is the pattern used during the search
| grep -rnw '<PATH>/<TO>/<SOMEWHERE>' -e '<TEXT>'
|
Count number of files in this directory and all sub-directories . look in current directory
-name looks for files with the following name
-iname ignores case of the name
-type restrict the results to files of a certain specified type
* wildcard matches any string of characters
? wildcard matches any single character
-ls shows additional information about files found
-maxdepth limits results to a max depth specified
-size looks for files with specified size
| find
find . -name "<FILE/DIRECTORY_NAME>"
find . -name "test*" -ls
find . -type f -name "test*" -ls
find . -type d -maxdepth 1
find . -size 0
|
Search all files and directories on the sys Uses a local DB to index all files, so it can be faster than find but also out of date (updates once per day) DB can be manually updated using sudo updatedb
| |
Search for a specific package | sudo dpkg --list | grep <PACKAGE_NAME>
|
Total disk space used (disk usage) by current directory and all sub-directories -h shows sizes in human readable format
-s summarize at the current depth
Shows size of all folders (and everything they contain) and files at the selected location
-a the all flag lists the sizes of all files and directories in the given file path. This option is often combined with the -h flag for ease of use. Notice the individual file sizes are listed with the directories.
-c Shows the total of all disk usage for the given file path as a new line at the bottom
* use for current location
| du -sh <LOCATION>
du -sh <LOCATION>/*
du -sh *
du -shc *
|
Shows size of directories -T shows type of directory
-h shows sizes in human readable format
| |
See if a service is running | service <service-name> status
service --status-all
|
Search terminal history Keep pressing to search through previous commands that match
| |
Shows running processes and Env Args I think the ww does line wrapping
| |
Unrar unrars to the directory you are currently in
| sudo unrar x <FILENAME>.rar
|
Run last command So to run the last command as sudo if you forget to add it to the start: sudo !!
| |
Open a file using sudo in a GUI application on Mac | sudo open -a <APPLICATION_NAME> /file/to/open
|
| |
Run command as a different user: sudo = be root so I can do anything.โโ su means "now be another userโ When you run su as root, you don't need to provide the users' password So "sudo su" means "run command as other user, and only have to enter root password"
| sudo su postgres -c "psql"
|
How to Kill Processes -15: the default way to kill a process -9: Last resort way to kill a process
| |
Terminal command history -c delete current session history
| |
Delete all terminal command history | |
| diff -arq /Diretory1 /Directory2
|
| sudo find / -type f -name โpg_hba.conf"
|
| find / -type d -name "post*"
|
Change user Leave empty to change to root user
| |
On a clean install, grant current user sudo powers | su
<ENTER ROOT PASSWORD>
echo "<USERNAME> ALL=(ALL) ALL" >
/etc/sudoers.d/<USERNAME>
chmod 440 /etc/sudoers.d/<USERNAME>
|
Shutdown / restart -h apparently this isn't actually needed
-r restarts instead of shutting down
now shuts it down immediately otherwise it will default to a 60 second delay
| sudo shutdown -r now
sudo shutdown -h 10:00 "Shutting down for scheduled maintenance."
|
Use a shell command in-line | ls -l $(dpkg --listfiles ftp)
|
Open an image from the command line | |
Alias a command persistently directly from the command line and reload terminal This is faster than opening the ~/.bashrc file manually and adding the line directly source ~/.bashrc reloads the new parameters into the current terminal session
| echo "alias ls='ls -la'" >> ~/.bashrc
source ~/.bashrc
|
| curl https://ipinfo.io/ip
|
Show interface configuration | |
| |
List all ip routing tables | ip route show table all | grep -Po 'table \K[^\s]+' | sort -u
|
Show content of ip routing table | ip route list table <TABLE_NAME>
|
| sudo ip route flush table <TABLE_NAME>
|
Disable and uninstall SSH | sudo systemctl stop ssh
sudo apt-get --purge remove ssh
|
rsync large files and directories -a archive (good for large files or unstable connections)
Keeps a record of both sides of transfer to make sure it is successful even if it drops out temporarily in the middle
-e specify remote shell to use
| sudo rsync -Pav -e "ssh -i $HOME/Keys/<SSH_KEYS>.pem" <SOURCE_LOCATION> <DEST_USER>@<DEST_IP>:<DEST_LOCATION>
sudo rsync -Pav -e "ssh -i $HOME/keys/Dev-Validator-Keys.pem" ~/TestDir ubuntu@172.31.31.109:~/ |
Find all files changed in the last 5 minutes starting at the / root directory not including the paths /pro/* and /sys*/ Show updated time next to each file and folder
| sudo find / -maxdepth 10 -not -path "/proc/*" -and -not -path "/sys/*" -mmin -5 -printf "%p %TY-%Tm-%Td %TH:%TM \n"
|
Change username -l flag to specify new name
| usermod -l <NEW_NAME> <OLD_NAME>
|
Change groupname -n flag to specify new name
| groupmod -n <NEW_NAME> <OLD_NAME>
|
UFW - Show all rules even when UFW is disabled | |
| tar -czvf archive.tar.gz stuff
|
| |
| tar -cJf archive.tar.xz stuff
|
| |
Show all available kernels | dpkg --list | grep linux-image
|
| |
| sudo apt remove -y linux-image-
|