Skip to content

Instantly share code, notes, and snippets.

@nicokosi
Last active September 22, 2016 03:20
Show Gist options
  • Save nicokosi/5352479 to your computer and use it in GitHub Desktop.
Save nicokosi/5352479 to your computer and use it in GitHub Desktop.
Basic Unix commands
# File basics:
############################
# list files, sorted by update date (recent last)
ls -rclt
# list files, sorted by update date (recent first)
ls -clt
# (recursive) folder sizes
du -h -d1 # human-readable sizes + dir depth of 1
# List the 20 biggest folders, in current directory
du -k | sort -nr | head -20
# file usage per mount point
df -h # human-readable sizes
# delete folder (recursively)
rm -Rf folder
# Search file content using multiple OR conditions
grep "ERROR\|WARN\|FATAL" *.log
# Search file content and display 3 lines for matches (output context):
grep -C 3 -R profile **/pom.xml
# Highlight the word 'foo' in a stream:
grep --color -E 'foo|$'
# or:
egrep --color 'foo|$'
# Search file named "filename":
find directory -name "filename"
# File archive manipulation:
############################
# list files in tar.gz archive file:
tar -tvf source.tar.gz
# extract tar archive:
tar -xf source.tar.gz -C output_dir
# create tar archive
tar -cf archive.tar file1 folder2
# unzip file:
unzip -C source.zip -d /output_dir
# shutdown/restart:
############################
# shutdown:
shutdown now
# restart:
shutdown -r now
# Misc
#################################
# Repeat a command every 10 seconds
watch "echo 'foo'" -n 10
# Brace expansion
ls src{Main,Test}.scala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment