Linux Basic Commands
Table of contents
π»π Basic Linux Commands You Must Know! π‘
Are you new to the exciting world of Linux? π§ Whether you're a tech enthusiast or just curious about this powerful operating system, learning a few basic commands can make your Linux journey smoother and more enjoyable. π
π ls - List Directory Contents πͺJust type "ls" in the terminal, and it will display all the files and directories in the current folder.
ls # list files or directories
ls -l #List the contents of the directory in a table format with columns including.
ls -a #List files or directories including hidden files or directories.
ls *.sh #List files has extension .sh
ls -i #List the files and directories with index numbers in oders A-Z
π touch - Create New Files With the "touch" command, you can create a new empty file in an instant! Simply type "touch filename.extension" and, ta-da! πͺ Your new file is ready to be filled with whatever you desire.
touch filename #Create empty file
touch file1.log #Creating empty logfile
π mkdir - Create Directories Want to organize your files into neat folders? The "mkdir" command is here to help! π Just type "mkdir foldername" to create a new directory. Keep your files tidy and find them easily later on.
mkdir /home/ubuntu/Mydirectory #Make a new folder in a ubuntu home location.
mkdir .NewFolder #Make a hidden directory (see carefully here (dot) . before a file to make it hidden)
#Make multiple directories at the same time.
mkdir -p A/B/C/D #nested directory -p specifies Parent.
π cd - Move Here & There You want to ride Anywhere!π΄ Change your position from one directory structure to another in many ways. Be the smart one to ride like a pro to win!π
cd /home/ubuntu/ #Go to the provided path.
cd ~ #Powerful command! Go to the home directory.
cd .. #Go to one step back.
cd ../.. #Go to two step back.
π cat - Display File Content Curious about what's inside a file? π΅οΈββοΈ Use the "cat" command to peek inside and see the contents of a file directly in the terminal. Just type "cat filename" and let the information flow!
cat filename.extension #See what this file contains
βοΈ cp - Copy Files and Directories Need to make a backup or duplicate a file or folder? The "cp" command is your friend. π€
#Copy file
cp file1.txt /tmp/file1.txt #copy file from current location to /temp folder
mkdir /home/ubuntu/folder{1..3} #Create folder1 folder2 folder3 in one go
mkdir /home/ubuntu/folderA
#you are now at /home/ubuntu
cp folder1 /bin/folderA #cp source destination
ποΈ rm - Remove Files and Directories The "rm" command allows you to delete unwanted files and directories. ποΈ But beware! Use it with caution, as deleted files are not recoverable.
rm file1.txt #Remove filename.extension
rmdir /myfolder #Remove Directory.
rm -rf /myfolder #Removes the entries for a specified file, group of files, or certain select files from a list within a directory
#-rf which allow it to delete non-empty directories forcefully.
rm -r /home/ubuntu #Remove all sub-directories and files -r means recursive.
rm *.yml #Remove file has perticular extention.
π vim - Simple Text Editor When you want to edit a file right in the terminal, "vim" is the answer! βοΈ Type "vim filename" to open this user-friendly text editor and start making changes by typing βiβ (insert) and save it by β:wq!β ; if you wish to not to save do β:q!β
π grep - Search Text Looking for specific information/string within files? The "grep" command can do the job! π Use "grep keyword filename" to find all occurrences of "keyword" in the given file.
grep -l "unix" * #Display the file names that matches the pattern
grep -i "UNix" file1.txt #Case insensitive search
grep -n "unix" geekfile.txt #Show line number while displaying the output using grep -n
π pwd - Print/Present Working Directory Lost in the terminal jungle? π³ The "pwd" command is like a compass; it shows you the full path of the current directory. Type "pwd" to know exactly where you are.
π history - What you have run so far! Do you want to know what you were doing on that black screenπ»; just a history command can tell you everything you have been running. π΅οΈ
That's it for now! These basic Linux commands will give you a solid foundation to explore and enjoy the world of Linux. π So, open your terminal and start experimenting. Happy Linux-ing! πππ§
Subscribe to my newsletter
Read articles from ashwini purwat directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by