Shell commands
Add
&
at the end of line to make the command run in background0
is true and1
is falseOnce you need a data-structure, use python
https://cheatography.com/davechild/cheat-sheets/linux-command-line/
View manual: man
β
- Section 0 - Everything
- Section 1 - User Commands
- Section 2 - System Calls (functions provided by the kernel)
- Section 3 - Subroutines (Library Calls)
- Section 4 - Special Files (like device files in /dev directory
- Section 5 - File Formats and Conversions e.g. /etc/passwd
- Section 6 - Games for Linux, self-explanatory
- Section 7 - Miscellaneous, e.g.Macro Packages and Conventions
- Section 8 - System Management Commands
- Section 9 - Kernel Routines
- Section n - New documentation, that may be moved to a more appropriate section.
- Section l - Local documentation referring to this particular system
See also man man
Show file structure: tree
β
Copy files: cp
β
If you need to copy files from your local computer to the computer you are accessing remotely, use the scp
command:
scp /localdirectory/example1.txt <username>@<remote>:<path>
will copy example1.txt to the specified <path>
on the remote computer. You can leave <path>
blank to copy to the root folder of the remote computer.
scp <username>@<remote>:/home/example1.txt ./
will move example1.txt
from the home directory on the remote computer to the current directory on the local computer.
Move/rename files: mv
β
Add alias: alias
β
Speeds up daily routine
alias [key]=[text]
# Do not include the flag -- or -
# in .bash_profile
alias runui="cd /c/workspace/;yarn dev"
Add path: export
β
export PATH=\$PATH:[/usr/sbin]
Install apps: apt
β
# update all apps
sudo apt update && sudo apt upgrade
# install app XXX
apt install [XXX]
# Variations to skip confirmation
sudo apt install --assume-yes
Change permission: chmod
β
# Grant user execution permission of file:
chmod u+x file
# Grant everyone all permissions
chmod 777
Link: ln
β
allows multiple filenames to be associated with the same file
Stream Editor: sed
β
Most common for text replacement
View processes: ps
β
ps -ef
# Flag -e means all processes
# Flag -f means show process details and flags
Concatenate: cat
β
conCATenate
Search: grep
β
Use --color flag to show matches in color!
Show logged on users: who
β
Divide a file: cut
β
Report or omit repeated lines: uniq
β
Word count: wc
β
Delete folder: rm -rf
β
Create new file: touch
β
Displaying data: od
β
displaying ("dumping") data in various human-readable output formats: Od -vtu1 filename The name is an acronym for "octal dump" since it defaults to printing in the octal data format
Translate: tr
β
# Replace line endings with comma
Tr '\r' ','
Extract: tar
β
tar -xf [file]
Shutdown/restart: shutdown
β
sudo shutdown -r
# force shutdown right away
sudo shutdown --reboot now
Check connection: ping
β
Download from remote: wget
β
- resumable transfer compare to copy/move
- https://curl.se/docs/comparison-table.html
# wget's major advantage over curl is it downloads recursively
wget [url]
## Transfer data: curl
curl -http2 [url]
curl [url]
SSH into remote: ssh
β
ssh [email protected] -p 7777
You'll be prompted to accept the hostβs key the first time you connect