Linux One-Liner Examples

Practical one-liner examples for common Linux tasks — file creation, moving, symlinking, and more.

Customer Ticket 1

Create 10 files named Report1, Report2, ..., Report10 in your home directory:

touch ~/Report{1..10} && date && ls ~/Report*

&& or ;

&& (Logical AND)

Used to chain commands where the second command only runs if the first succeeds. Use this when you want each step to depend on the previous one completing without error.

; (Semicolon)

Runs commands in sequence regardless of whether the previous command succeeds or fails. Use this when steps are independent of each other.

Customer Ticket 2

mkdir /home/student/marketing && mv /home/student/Report* /home/student/marketing/ && touch /home/student/marketing/ReadMe && echo "Reports for each year will be organized into directories named for each corresponding year - ell" > /home/student/marketing/ReadMe

But can I make it shorter?

Use the tilde ~ to represent /home/student and combine the commands more concisely:

mkdir ~/marketing && mv ~/Report* ~/marketing/ && echo "Reports for each year will be organized into directories named for each corresponding year - ell" > ~/marketing/ReadMe && cat ~/marketing/ReadMe

Customer Ticket 3

rm ~/Report{2..10} && mv ~/Report1 ~/SeptemberReport && ls -l ~/

Creating a symlink

ln -s /path/to/original/file /path/to/symlink

Red Hat Chapter 3

Task: Create a directory Thesis, subdirectories Chapter1 through Chapter5, and inside Thesis/Chapter3 create a file called lesson1.

mkdir -p Thesis/Chapter{1..5} && touch Thesis/Chapter3/lesson1 && ls -R Thesis