This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
linuxfind [2021/05/12 21:44] bpienig |
linuxfind [2021/05/12 22:11] bpienig |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Linux Cheat Sheet ====== | ====== Linux Cheat Sheet ====== | ||
The contents of this file are released under the GNU General Public License. Feel free to reuse the contents of this work, as long as the resultant works give proper attribution and are made publicly available under the GNU General Public License. | The contents of this file are released under the GNU General Public License. Feel free to reuse the contents of this work, as long as the resultant works give proper attribution and are made publicly available under the GNU General Public License. | ||
- | |||
===== Basics ===== | ===== Basics ===== | ||
- | ==== Getting help ==== | + | ==== Getting help ==== |
- | | + | View the manual for target command |
<file bash>man command</ | <file bash>man command</ | ||
- | * Get help with a target command (probably the same as above, but not always): | + | Get help with a target command (probably the same as above, but not always): |
<file bash> | <file bash> | ||
- | * In case you forget the name of a command, print possible commands relating to any given word: | + | In case you forget the name of a command, print possible commands relating to any given word: |
<file bash> | <file bash> | ||
- | * View index of help pages: | + | View index of help pages: |
<file bash> | <file bash> | ||
- | ===== Command Line Utilities | + | ==== Command Line Utilities ==== |
- | ==== Basic File and Directory Operations | + | === Basic File and Directory Operations === |
- | | + | Print current working directory: |
<file bash> | <file bash> | ||
- | * Show files in current directory: | + | Show files in current directory: |
<file bash> | <file bash> | ||
- | * Show maximum information about all files, including hidden: | + | Show maximum information about all files, including hidden: |
<file bash>ls -a</ | <file bash>ls -a</ | ||
- | * Recurse into subdirectories and list those as well: | + | Recurse into subdirectories and list those as well: |
<file bash>ls -R</ | <file bash>ls -R</ | ||
- | * List files by modification time, most recent first. | + | List files by modification time, most recent first. |
<file bash>ls -lt</ | <file bash>ls -lt</ | ||
- | * Move/rename a file or directory (be careful that you don't move the source over a destination with the same name): | + | Move/rename a file or directory (be careful that you don't move the source over a destination with the same name): |
<file bash>mv source destination</ | <file bash>mv source destination</ | ||
- | * Delete target forever (be very careful), use -r recursive flag for directories: | + | Delete target forever (be very careful), use -r recursive flag for directories: |
<file bash>rm target</ | <file bash>rm target</ | ||
- | * Copy file or directory: | + | Copy file or directory: |
<file bash>cp source destination</ | <file bash>cp source destination</ | ||
- | * Mount filesytem: | + | Mount filesytem: |
<file bash> | <file bash> | ||
- | * Unmount: | + | Unmount: |
<file bash> | <file bash> | ||
- | * Forensically clone filesystems and do other low-level operations on files. Be careful with this one. Can be destructive: | + | Forensically clone filesystems and do other low-level operations on files. Be careful with this one. Can be destructive: |
<file bash> | <file bash> | ||
- | * Work with disk partitions: | + | Work with disk partitions: |
<file bash> | <file bash> | ||
- | * Filesystem creation tool: | + | Filesystem creation tool: |
<file bash> | <file bash> | ||
- | ==== System Administration | + | === System Administration === |
- | | + | Execute command as an administrator (can be destructive/ |
<file bash> | <file bash> | ||
- | * Become system administrator: | + | Become system administrator: |
<file bash> | <file bash> | ||
- | * Quit system administration: | + | Quit system administration: |
<file bash> | <file bash> | ||
- | * Forgot to type sudo in front of a command and already hit enter? Repeat the last command using sudo: | + | Forgot to type sudo in front of a command and already hit enter? Repeat the last command using sudo: |
<file bash> | <file bash> | ||
- | ==== Installing software from a .tgz (also known as a tarball) | + | === Installing software from a .tgz (also known as a tarball) === |
- | | + | First, unzip the tarball (see section on tar, below) |
- | | + | Next, move into unzipped directory |
<file bash>cd software_directory</ | <file bash>cd software_directory</ | ||
- | * Always read README first if it is provided, in case there are any modifications to the procedure outlined below: | + | Always read README first if it is provided, in case there are any modifications to the procedure outlined below: |
<file bash>cat README</ | <file bash>cat README</ | ||
- | * Automatically check for appropriate configurations and generate a MAKE file in the directory: | + | Automatically check for appropriate configurations and generate a MAKE file in the directory: |
<file bash> | <file bash> | ||
- | * Compile software. May require sudo: | + | Compile software. May require sudo: |
<file bash> | <file bash> | ||
- | * Move files into their appropriate locations. May also require sudo: | + | Move files into their appropriate locations. May also require sudo: |
<file bash> | <file bash> | ||
- | * Clean up files in directory, in case make command fails, or just to remove unnecessary cruft: | + | Clean up files in directory, in case make command fails, or just to remove unnecessary cruft: |
<file bash> | <file bash> | ||
- | ==== Ubuntu/ | + | === Ubuntu/ |
- | | + | Check distro repositories for software updates: |
<file bash> | <file bash> | ||
- | * Download and install updates (update first): | + | Download and install updates (update first): |
<file bash> | <file bash> | ||
- | * Search for package in the repositories: | + | Search for package in the repositories: |
<file bash> | <file bash> | ||
- | * Get more detail on one specific package: | + | Get more detail on one specific package: |
<file bash> | <file bash> | ||
- | * Download and install a package: | + | Download and install a package: |
<file bash> | <file bash> | ||
- | * View the output of a command in a more convenient format: | + | View the output of a command in a more convenient format: |
<file bash> | <file bash> | ||
- | ==== Working With Files ==== | + | === Working With Files === |
- | | + | Print a file in terminal: |
<file bash>cat file</ | <file bash>cat file</ | ||
- | * Find files matching filename: | + | Find files matching filename: |
<file bash> | <file bash> | ||
- | * See the version of a program or the location of the program | + | See the version of a program or the location of the program |
<file bash> | <file bash> | ||
- | * Search through filename for matches to phrase: | + | Search through filename for matches to phrase: |
<file bash> | <file bash> | ||
- | * Search through output of a command for phrase: | + | Search through output of a command for phrase: |
<file bash> | <file bash> | ||
</ | </ | ||
- | ==== Working With Processes | + | === Working With Processes === |
- | | + | List all running processes: |
<file bash>ps -e</ | <file bash>ps -e</ | ||
- | * Standard system monitor showing a more extensive view of all processes and system resources: | + | Standard system monitor showing a more extensive view of all processes and system resources: |
<file bash> | <file bash> | ||
- | * Like top, but with a better, cleaner interface: | + | Like top, but with a better, cleaner interface: |
<file bash> | <file bash> | ||
- | * Stop a process from using all system resources and lagging computer: | + | Stop a process from using all system resources and lagging computer: |
<file bash> | <file bash> | ||
- | * Kill misbehaving process (use sparingly, last resort, try ' | + | Kill misbehaving process (use sparingly, last resort, try ' |
<file bash> | <file bash> | ||
- | * Start a process in the background | + | Start a process in the background |
<file bash> | <file bash> | ||
- | * Start a process in the background and have it keep running after you log off | + | Start a process in the background and have it keep running after you log off |
<file bash> | <file bash> | ||
</ | </ | ||
- | ==== Compression and Encryption | + | === Compression and Encryption === |
- | | + | Make a simple compressed backup of files or directories: |
<file bash>tar -cvzf backup/ | <file bash>tar -cvzf backup/ | ||
- | * Open a compressed .tgz or .tar.gz file: | + | Open a compressed .tgz or .tar.gz file: |
<file bash>tar -xvf target.tgz</ | <file bash>tar -xvf target.tgz</ | ||
- | * Encrypt a file: | + | Encrypt a file: |
<file bash>gpg -o outputfilename.gpg -c target_file</ | <file bash>gpg -o outputfilename.gpg -c target_file</ | ||
- | * Decrypt a file: | + | Decrypt a file: |
<file bash>gpg -o outputfilename -d target.gpg</ | <file bash>gpg -o outputfilename -d target.gpg</ | ||
- | * Zip and encrypt a directory simultaneously: | + | Zip and encrypt a directory simultaneously: |
<file bash> | <file bash> | ||
- | ===== The Bash shell ===== | + | ==== The Bash shell ==== |
- | ==== File Name expansions | + | === File Name expansions === |
- | | + | Current user's home directory: |
<file bash> | <file bash> | ||
- | * Current directory: | + | Current directory: |
<file bash> | <file bash> | ||
- | * Parent directory: | + | Parent directory: |
<file bash> | <file bash> | ||
- | * Or even (Two parent directories down): | + | Or even (Two parent directories down): |
<file bash> | <file bash> | ||
- | * All files in target directory. (Be very careful.): | + | All files in target directory. (Be very careful.): |
<file bash>/* | <file bash>/* | ||
</ | </ | ||
- | ==== Output Redirects | + | === Output Redirects === |
- | | + | Redirect output of one command into the input of another with a pipe: |
<file bash> | <file bash> | ||
- | * Or even: | + | Or even: |
<file bash> | <file bash> | ||
- | * Redirect output to a file: | + | Redirect output to a file: |
<file bash> | <file bash> | ||
- | * Or: | + | Or: |
<file bash> | <file bash> | ||
- | * Or even, to redirect in a different direction: | + | Or even, to redirect in a different direction: |
<file bash> | <file bash> | ||
- | * Append output rather than writing over the target file: | + | Append output rather than writing over the target file: |
<file bash> | <file bash> | ||
- | * Works like |, but it writes output to both target and terminal: | + | Works like |, but it writes output to both target and terminal: |
<file bash>tee target</ | <file bash>tee target</ | ||
- | * Redirect standard output and error to /dev/null, where it is deleted. | + | Redirect standard output and error to /dev/null, where it is deleted. |
<file bash> | <file bash> | ||
</ | </ | ||
- | ==== Controlling Execution | + | === Controlling Execution === |
- | | + | Wait until command 1 is finished to execute command 2 |
<file bash> | <file bash> | ||
- | * Or even: | + | Or even: |
<file bash> | <file bash> | ||
- | * && acts like ; but only executes command2 if command1 | + | && acts like ; but only executes command2 if command_1 |
<file bash> | <file bash> | ||
- | * || acts like && but only executes | + | double pipes || act like && but only executes |
<file bash> | <file bash> | ||
</ | </ | ||
- | ==== Bash Wildcards | + | === Bash Wildcards === |
- | | + | Zero or more characters: |
<file bash> | <file bash> | ||
- | * Matches " | + | Matches " |
<file bash> | <file bash> | ||
- | * Matches any incidences of " | + | Matches any incidences of " |
<file bash> | <file bash> | ||
- | * Matches any one char: | + | Matches any one char: |
<file bash>?</ | <file bash>?</ | ||
- | * Matches any of the characters listed inside brackets: | + | Matches any of the characters listed inside brackets: |
<file bash> | <file bash> | ||
- | * Matches a range of chars between a-z: | + | Matches a range of chars between a-z: |
<file bash> | <file bash> | ||
===== Advanced ===== | ===== Advanced ===== | ||
==== Command Line Utilities, Continued ==== | ==== Command Line Utilities, Continued ==== | ||
- | ==== Networking | + | === Networking === |
- | | + | Configure network interfaces: |
<file bash> | <file bash> | ||
- | * Configure wireless network interfaces: | + | Configure wireless network interfaces: |
<file bash> | <file bash> | ||
- | * Connect to a remote server. | + | Connect to a remote server. |
<file bash>ssh username@ip_address</ | <file bash>ssh username@ip_address</ | ||
- | * Forward X from target to current machine (Get a remote desktop. Somewhat obscure, but very useful): | + | Forward X from target to current machine (Get a remote desktop. Somewhat obscure, but very useful): |
<file bash>ssh -X username@ip_address</ | <file bash>ssh -X username@ip_address</ | ||
- | * Copy files/ | + | Copy files/ |
<file bash>scp -r source_filename: | <file bash>scp -r source_filename: | ||
- | * Copy only changes between files or directories (super efficient way to sync directories, | + | Copy only changes between files or directories (super efficient way to sync directories, |
<file bash> | <file bash> | ||
- | * Check to see if target is online and responding | + | Check to see if target is online and responding |
<file bash> | <file bash> | ||
- | * View network route to target: | + | View network route to target: |
<file bash> | <file bash> | ||
- | * Network Monitor | + | Network Monitor |
<file bash> | <file bash> | ||
- | * View firewall rules | + | View firewall rules |
<file bash> | <file bash> | ||
- | * Scan this machine(localhost) to check for open ports: | + | Scan this machine(localhost) to check for open ports: |
<file bash> | <file bash> | ||
- | ==== wget ==== | + | == wget == |
- | | + | download a file over http: |
<file bash> | <file bash> | ||
- | * complete a partially downloaded file: | + | complete a partially downloaded file: |
<file bash> | <file bash> | ||
- | * start download in background: | + | start download in background: |
<file bash> | <file bash> | ||
- | * download a file from ftp server: | + | download a file from ftp server: |
<file bash> | <file bash> | ||
- | ==== netcat | + | == netcat == |
- | | + | Listen for input from network on recieving_port, |
<file bash> | <file bash> | ||
- | * Pipe the output of a command to a target ip and port over the network: | + | Pipe the output of a command to a target ip and port over the network: |
- | <file bash> | + | <file bash> |
- | | + | Use tar to compress and output a file as a stream, pipe it to a target ip and port over the network: |
- | <file bash> | + | <file bash> |
- | </ | + | === Users and Groups === |
- | ==== Users and Groups | + | Change owner of a file or directory: |
- | | + | <file bash> |
- | <file bash> | + | Change privileges over file or directory (see man page for details.) |
- | | + | |
<file bash> | <file bash> | ||
- | * Create a new user: | + | Create a new user: |
<file bash> | <file bash> | ||
- | * Change user privileges (be very careful with this one): | + | Change user privileges (be very careful with this one): |
<file bash> | <file bash> | ||
- | * Delete user | + | Delete user |
<file bash> | <file bash> | ||
- | * Print groups: | + | Print groups: |
<file bash> | <file bash> | ||
- | * Create a new group: | + | Create a new group: |
<file bash> | <file bash> | ||
- | * Change group privileges: | + | Change group privileges: |
<file bash> | <file bash> | ||
- | * Delete group: | + | Delete group: |
<file bash> | <file bash> | ||
- | * Temporarily become a different user: | + | Temporarily become a different user: |
<file bash>su username</ | <file bash>su username</ | ||
- | * Print usernames of logged in users: | + | Print usernames of logged in users: |
<file bash> | <file bash> | ||
- | * Write one line to another user from your terminal: | + | Write one line to another user from your terminal: |
<file bash> | <file bash> | ||
- | * Interactive talk program to talk to other users from terminal (must be installed from repositories.): | + | Interactive talk program to talk to other users from terminal (must be installed from repositories.): |
<file bash> | <file bash> | ||
- | ==== Working With Files, Continued | + | === Working With Files, Continued === |
- | | + | View what processes are using what files: |
<file bash> | <file bash> | ||
- | * View the differences between two files: | + | View the differences between two files: |
- | <file bash> | + | <file bash> |
- | | + | Output the top numberoflines of file: |
- | <file bash> | + | <file bash> |
- | | + | Like head, but it outputs the last -n lines: |
- | <file bash> | + | <file bash> |
- | | + | Checksum a file: |
<file bash> | <file bash> | ||
- | * Checksum every file in a directory (install this one from repositories.): | + | Checksum every file in a directory (install this one from repositories.): |
<file bash> | <file bash> | ||
- | * Checksum a file (better algorithm with no hash collisions): | + | Checksum a file (better algorithm with no hash collisions): |
<file bash> | <file bash> | ||
- | * Same operation as md5deep, but using sha1: | + | Same operation as md5deep, but using sha1: |
<file bash> | <file bash> | ||
- | * Call command every few numberofseconds, | + | Call command every few numberofseconds, |
- | <file bash> | + | <file bash> |
- | | + | Execute command, print how long it took: |
<file bash> | <file bash> | ||
- | * View files in directory from largest to smallest: | + | View files in directory from largest to smallest: |
<file bash>du -a directory | sort -n -r | less</ | <file bash>du -a directory | sort -n -r | less</ | ||
- | * remove spaces from filenames in current directory: | + | remove spaces from filenames in current directory: |
<file bash> | <file bash> | ||
- | * change capitals to lowercase in filenames in current directory: | + | change capitals to lowercase in filenames in current directory: |
<file bash> | <file bash> | ||
==== Environment and Hardware ==== | ==== Environment and Hardware ==== | ||
- | * print motherboard information | + | print motherboard information |
<file bash> | <file bash> | ||
- | * Print full date and time: | + | Print full date and time: |
<file bash> | <file bash> | ||
- | * Print the hostname of this machine: | + | Print the hostname of this machine: |
<file bash> | <file bash> | ||
- | * Print information about current linux distro: | + | Print information about current linux distro: |
<file bash> | <file bash> | ||
- | * Or even: | + | Or even: |
<file bash> | <file bash> | ||
- | * Print linux kernel version: | + | Print linux kernel version: |
<file bash> | <file bash> | ||
- | * Print information about kernel modules: | + | Print information about kernel modules: |
<file bash> | <file bash> | ||
- | * Configure kernel modules (never do this ;p ): | + | Configure kernel modules (never do this ;p ): |
<file bash> | <file bash> | ||
- | * View Installed packages: | + | View Installed packages: |
<file bash> | <file bash> | ||
- | * Print environment variables: | + | Print environment variables: |
<file bash> | <file bash> | ||
- | * List hardware connected via PCI ports: | + | List hardware connected via PCI ports: |
<file bash> | <file bash> | ||
- | * List hardware connected via USB ports: | + | List hardware connected via USB ports: |
<file bash> | <file bash> | ||
- | * Print hardware info stored in BIOS: | + | Print hardware info stored in BIOS: |
<file bash> | <file bash> | ||
- | * Dump captured data off of wireless card: | + | Dump captured data off of wireless card: |
<file bash> | <file bash> | ||
- | * Dump info about keyboard drivers: | + | Dump info about keyboard drivers: |
<file bash> | <file bash> | ||
- | ==== Ubuntu | + | ==== System Administration, |
- | | + | Add a Personal Package Archive from Ubuntu Launchpad: |
<file bash> | <file bash> | ||
- | * Install a .deb file from command line: | + | Install a .deb file from command line: |
<file bash> | <file bash> | ||
</ | </ | ||
- | ==== Python | + | ==== Development |
- | | + | === Python === |
+ | Update pip (Python package manager): | ||
<file bash>pip install -U pip</ | <file bash>pip install -U pip</ | ||
- | * search pip repos for a library: | + | search pip repos for a library: |
<file bash>pip search library_name</ | <file bash>pip search library_name</ | ||
- | * create a virtual python environment to allow install of many different versions of the same Python modules: | + | create a virtual python environment to allow install of many different versions of the same Python modules: |
<file bash> | <file bash> | ||
- | * connect to a virtual python environment | + | connect to a virtual python environment |
<file bash> | <file bash> | ||
- | * disconnect from a virtual python environment: | + | disconnect from a virtual python environment: |
<file bash> | <file bash> | ||
- | * install package into virtual python environment from outside: | + | install package into virtual python environment from outside: |
<file bash>pip install packagename==version_number -E dirname</ | <file bash>pip install packagename==version_number -E dirname</ | ||
- | * export python virtual environment into a shareable format: | + | export python virtual environment into a shareable format: |
<file bash>pip freeze -E dirname > requirements.txt</ | <file bash>pip freeze -E dirname > requirements.txt</ | ||
- | * import python virtual environment from a requirements.txt file: | + | import python virtual environment from a requirements.txt file: |
<file bash>pip install -E dirname -r requirements.txt | <file bash>pip install -E dirname -r requirements.txt | ||
</ | </ | ||
- | ==== git ==== | + | === GIT === |
All commands must be performed in the same directory as .git folder | All commands must be performed in the same directory as .git folder | ||
- | | + | |
+ | Start a new git project: | ||
<file bash>git init | <file bash>git init | ||
git config user.name " | git config user.name " | ||
git config user.email " | git config user.email " | ||
- | * Make a copy of a git (target can be specified either locally or remotely, via any number of protocols): | + | Make a copy of a git (target can be specified either locally or remotely, via any number of protocols): |
<file bash>git clone target</ | <file bash>git clone target</ | ||
- | * Commit changes to a git: | + | Commit changes to a git: |
<file bash>git commit -m " | <file bash>git commit -m " | ||
- | * Get info on current repository: | + | Get info on current repository: |
<file bash>git status</ | <file bash>git status</ | ||
- | * Show change log for current repository: | + | Show change log for current repository: |
<file bash>git log</ | <file bash>git log</ | ||
- | * Update git directory from another repository: | + | Update git directory from another repository: |
<file bash>git pull [target]</ | <file bash>git pull [target]</ | ||
- | * Push branch to other repository: | + | Push branch to other repository: |
<file bash>git push [target]</ | <file bash>git push [target]</ | ||
- | * Create a new branch: | + | Create a new branch: |
<file bash>git branch [branchname]</ | <file bash>git branch [branchname]</ | ||
- | * Switch to target branch: | + | Switch to target branch: |
<file bash>git checkout [branchname]</ | <file bash>git checkout [branchname]</ | ||
- | * Delete a branch: | + | Delete a branch: |
<file bash>git branch -d [branchname]</ | <file bash>git branch -d [branchname]</ | ||
- | * Merge two branches: | + | Merge two branches: |
<file bash>git merge [branchname] [branchname]</ | <file bash>git merge [branchname] [branchname]</ | ||
- | * Show all branches of a project: | + | Show all branches of a project: |
<file bash>git branch | <file bash>git branch | ||
</ | </ | ||
- | ==== Virtualization ==== | + | === MySQL === |
- | * clone a virtual machine (this works, it's been tested): | + | Get help: |
- | <file bash> | + | |
- | * mount a shared virtual folder: | + | |
- | * you need to make sure you have the right kernel modules. You can do this with modprobe, but this package works instead in a ubuntu-specific way. | + | |
- | <file bash> | + | |
- | sudo mount -t vboxsf name/ | + | |
- | </ | + | |
- | ==== mysql ==== | + | |
- | | + | |
<file bash> | <file bash> | ||
- | * Show databases: | + | Show databases: |
<file bash> | <file bash> | ||
- | * Choose a database to use: | + | Choose a database to use: |
<file bash>use database/ | <file bash>use database/ | ||
- | * Show database schema: | + | Show database schema: |
<file bash> | <file bash> | ||
- | * Delete database: | + | Delete database: |
<file bash> | <file bash> | ||
- | * New database: | + | New database: |
<file bash> | <file bash> | ||
- | * Create a new user: | + | Create a new user: |
<file bash> | <file bash> | ||
- | * Show users: | + | Show users: |
<file bash> | <file bash> | ||
- | * Delete a user: | + | Delete a user: |
<file bash> | <file bash> | ||
- | * Give user access to all tables (make them root). the " | + | Give user access to all tables (make them root). the " |
<file bash> | <file bash> | ||
- | * give certain privileges to a user on a certain database: | + | give certain privileges to a user on a certain database: |
<file bash> | <file bash> | ||
- | * Tell mysql to use new user priv policies: | + | Tell mysql to use new user priv policies: |
<file bash> | <file bash> | ||
- | * change user password: | + | change user password: |
<file bash>use mysql; | <file bash>use mysql; | ||
- | update user set password='password'(' | + | update user set password=password(' |
- | | + | mysql command line args: |
- | | + | export text file with commands to rebuild all mysql tables: |
<file bash> | <file bash> | ||
- | * restore from a dump: | + | restore from a dump: |
<file bash> | <file bash> | ||
- | * dump entire database: | + | dump entire database: |
<file bash> | <file bash> | ||
- | * restore from entire database dump: | + | restore from entire database dump: |
- | <file bash> | + | <file bash> |
+ | ==== Virtualization ==== | ||
+ | clone a virtual machine (this works, it's been tested): | ||
+ | <file bash> | ||
+ | mount a shared virtual folder: | ||
+ | you need to make sure you have the right kernel modules. You can do this with modprobe, but this package works instead in a ubuntu-specific way. | ||
+ | <file bash> | ||
+ | sudo mount -t vboxsf name/ | ||
+ | </ | ||