Linux Basic Commands

Β·

4 min read

πŸ’»πŸ” 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! πŸ˜ŠπŸŽ‰πŸ§

Β