Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.
mv file dir/ && cd "$_" && pwd
find . -name node_modules -exec rm -rf {} +
find . -type d -newermt "2019-01-01" ! -newermt "2019-02-01" -exec ls -ld {} \;
(shopt -s dotglob; ls -1d "$PWD"/*)
(IFS=';'; mkdir $(locale mon))
cwd=$(cd "$(dirname "$0")" && pwd)
mkcd(){ NAME=$1; mkdir -p "$NAME"; cd "$NAME"; }
git archive master some/project/subdir | tar t
find . -type f -iname '*.un~' | while read UNDOFILE ; do FILE=$( echo "$UNDOFILE" | sed -r -e 's/.un~$//' -e 's&/\.([^/]*)&/\1&' ) ; [[ -e "$FILE" ]] || rm "$UNDOFILE" ; done
GITFOLDER="/srv/some/folder" ls-files --others --exclude-standard | tar czf ${GITFOLDER}-archives/uploads-$(date '+%Y%m%d%H%M').tar.gz -T -
lsof / | awk '$7 > 1048576 { print $7 / 1048576 "MB", $9, $1 }' | sort -nu | tail
[[ $(find /path/to/file -type f -size +51200c 2>/dev/null) ]] && echo true || echo false
svn add . --force
find /some/path -type f ! -perm -111 -ls
find /directory1/directory2/ -maxdepth 1 -type f | sort | tail -n 5 | xargs md5sum
ls | grep '....-..-..-......' | xargs -I {} bash -c "[[ x{} < x$(date -d '3 days ago' +%Y-%m-%d-%H%M%S) ]] && rm -rfv {}"
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
for name in *; do mv "$name" "${name,,}"; done
find /path/to/dir1 -printf "%U %G %m %p\n" > /tmp/dir1.txt
find . -name 'filename' | xargs -r ls -tc | head -n1
zip --filesync -r /path/to/out.zip /path/to/dir
install -b -m 600 /dev/null NEWFILE
for i in $(cat /var/log/vsftpd.log | grep $DATE_TIME | grep UPLOAD | grep OK); do ls /FTP/HOME/$i >> /dev/null 2> \&1; if \[ $? = 0 \]; then echo "$i" >> $FILES_OK_UPLOADS.log; else echo "$DATE ERROR: File $i not found" >> $FTP_FILES_NOTOK_$DATE_TIME.log; fi; done
find /path/to/dir -type d -exec chmod 0755 '{}' \; -o -type f -exec chmod 0644 '{}' \;
du -hsx * | sort -rh