Last active
December 23, 2019 17:25
-
-
Save mb0017/afbbbad8a34e4a88fafe to your computer and use it in GitHub Desktop.
Linux cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--- install/remove packages | |
apt-get update # Fetches the list of available updates | |
apt-get upgrade # Strictly upgrades the current packages | |
apt-get dist-upgrade # Installs updates (new ones) | |
apt-get autoclean # This command removes .deb files for packages | |
# that are no longer installed on your system. | |
apt-get clean # Remove the installed deb packages | |
apt-get remove <package> # This command removes an installed package, leaving configuration files intact. | |
apt-get purge <package> # This command completely removes a package and the associated configuration files. | |
apt-get autoremove #This command removes packages that were installed by other packages and are no longer needed. | |
apt-get autoremove <package> #This command removes an installed package and dependencies. | |
dpkg-query -l # List all packages installed | |
dpkg-query -l 'foo*' # List packages using a search pattern | |
apt-cache search 'foo' # Search for the package that you want to install | |
pwd # Print the current directory | |
history # Show the history of command lines executed up to this moment. | |
Commands prepend by a space will be executed but won't show up in the history. | |
After the user logs out from Bash, history is saved into ~/.bash_history | |
!n # Execute command number n in the command line history | |
history -c # Delete command line history | |
uname -a # Print system information | |
#--- disk space | |
df -l # Disk free, used to display the amount of available disk space | |
du -hc --max-depth=1 # Display space used by each directory | |
env # Display the environment variables | |
#--- print files | |
cat myfile # Print a text file | |
cat myfile1 myfile2 > myfile3 # Concatenate text files | |
head myfile # Print the first 10 lines of a text file | |
head -n 10 myfile | |
tail myfile # Print the last 10 lines of a text file | |
tail -n 10 myfile | |
#--- search files | |
grep -iRl 'text' # Find filenames that contain 'text' | |
grep -rnw 'text' # Find 'text' in files (r:recursive, n:linenum, w:whole word) | |
ack 'text' # Find 'text' in files (install: ack-grep in ubuntu) | |
nl myfile # Prepend line numbers to a text file | |
wc myfile # Print the number of lines, words, and bytes of a text file | |
uniq myfile # Print the unique lines of a text file, omitting consecutive identical lines | |
sort myfile # Sort alphabetically the lines of a text file | |
expand myfile # Convert tabs into spaces | |
unexpand myfile # Convert spaces into tabs | |
sed s/foo/bar/ myfile # Stream Editor: Replace the first occurrence of foo with bar | |
sed s/foo/bar/g myfile # Replace all occurrences of foo with bar | |
tr a-z A-Z <myfile # Translate characters: Convert all lowercase into uppercase in a text file | |
tr [:lower:] [:upper:] <myfile | |
#--- copying/moving/removing | |
cp myfile myfile2 # Copy a file | |
cp myfile mydir/ # Copy a file to a directory | |
mv myfile myfile2 # Rename a file | |
mv myfile mydir/ # Move a file to a directory | |
rm myfile # Delete a file | |
rm -rf <dir> # Remove a directory | |
ln -s <target dir/file> ./[SHORTCUT] # Create a symbolic link | |
mkdir mydir # Create a directory | |
touch myfile # Change access/modification timestamp on a file, creating it if it doesn't exist | |
#--- jobs/monitoring | |
ps -ef (UNIX options) # List all processes | |
top # Monitor processes in realtime | |
htop | |
jobs # List all jobs (i.e. processes whose parent is a Bash shell) | |
ctrl-Z # Suspend a job, putting it in the stopped state (send a SIGTSTP) | |
bg %1 # Put job #1 in the background (send a SIGCONT) | |
fg %1 # Resume job #1 in the foreground and make it the current job (send a SIGCONT) | |
kill %1 # Kill job #1 | |
#--- various | |
ldd --version # check to see which C library version is used. | |
whereis <library> # find location of shared library (ex. whereis libc.so) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment