Welcome to bashoneliners.com, a growing collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We review and improve every contributed one-liner to make sure it is 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.
some_command >| output.txt
ipadm create-addr -T static -a 192.168.1.10/24 eth0/staticaddr
sox -t ossdsp -w -s -r 44100 -c 2 /dev/dsp -t raw - | lame -x -m s - File.mp3
vim +'hardcopy > output.ps' +q style.css
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
printf '%s\n' ',s/^Exec=[^ ]*/& -s/' w q | ed /usr/share/applications/gimp.desktop
sudo sed -i 's/^Exec=[^ ]*/& -s/' /usr/share/applications/gimp.desktop
less -F FILE1
{ echo some text; echo; tail -n1 /var/log/apache2/error.log; } >> /path/to/file
echo -e "From: me\n\n$(tail -n1 /var/log/apache2/error.log)" >> file
ssh user@server bash < /path/to/local/script.sh
sed -e 's/^./\U&/' -e 's/_./\U&/g' -e 's/_/ /g' /path/to/input
find /path/to/dir -type d -exec chmod 0755 '{}' \; -o -type f -exec chmod 0644 '{}' \;
faad -o tmp.wav music.m4a && lame -b 192 tmp.wav music.mp3
do_something.sh &> out.log
encfs -i 5 $PWD/raw $PWD/content
dd if=/dev/sda bs=$(hdparm -i /dev/sda | grep BuffSize | cut -d ' ' -f 3 | tr [:lower:] [:upper:] | tr -d BUFFSIZE=,) conv=noerror | dd of=image.dd conv=noerror
screen -d -m -S some_name ping my_router
xxd /path/to/binary/file
ifconfig | grep ^en1 -A5 | grep inet | head -n 1
sed -n '\@interface Ethernet3/1@,/!/ s/ip address/&/p' file...
awk '/interface Ethernet3\/1/ {instanza=1} /!/ {instanza=0} instanza && /ip address/ {print}' file...
du -hsx * | sort -rh
find /path/to/dir -type l -exec sh -c 'cp --remove-destination "$(readlink "{}")" "{}"' \;
chage -d 0 USERNAME