Basic Linux Commands
Here, You i’ll get familar with the basic linux commands.
man — describes what does the given command does. Ex -> man ls
Directory Operations
cd — change directory (you can also use absolute paths,which start from the root folder /)
$ cd.mkdir — create or make directories
$ mkdir my_directorymkdir -p — make multiple nested folders (mkdir -p fruits/apple)
$ mkdir -p my_directory/onermdir — removes an empty directory. (use rm -r to remove not empty directory)
$ rm -r file nameBasic File Operations
ls — list the directory contents.
lspwd — tells the path of the directory you are in
pwdtree- list out all the directories and files in a tree like format
tree directory namecp -> copy files and directories (To copy a folder use -r along with cp)
cp -r source direcotry to destination directorymv — move (rename ) files. ex-> mv myname yourname (rename)
mv file.txtln — Used to create links, its like a pointer to another file.
FIle Viewing
less — shows the content stored in a file.
less large_file.txttail — watches for file changes by opening the file at the end
tail filecat — prints a file’s content to the standard output:
cat -n file1 // prints along with the number of linestouch — create file if not exist
chmod — change the permission of a file named. ‘file.txt’ tp read , write , and execute for the owner, & read only for others
chmod 755 file.txtchown — The owner (and the root user) can change the owner to another user using this. (change file owner)
chown <owner> <file>
chown -R <owner> <file> // changes the owner to directory , subdirectory within itdf- get disk usage information
df -h <directory>du — calculate the size of a directory as a whole
- du * — calculate the size of each file individually:
- du -g -h(-m) — displays in the said bytes
chown <owner> <file>
chown -R <owner> <file> // changes the owner to directory , subdirectory withinsudo — update package list using “apt”with super user privileges
sudo apt updateapt — install a package named “package-name”.
sudo apt install package-name touch — create a new file named “newfile.txt”
touch newfile.txtcat — Display the content of a file name “file.txt”
cat file.txtless — view the content of a large file name “large_file.txt”
less large_file.txtmore — view the content of a file named “file.txt” page by page
more file.txtrsync — synchronize the contents of two directories “source-directory” and “destination-directory”
rsyncFile Location
Get Mustansirraza’s stories in your inbox
Join Medium for free to get updates from this writer.
find — used to find files or folders matching a particular search pattern. It searches recursively.
- Find all the files under the current tree that have the
.jsextension and print the relative path of each file that matches:
find . -name '*.js'- Find directories under the current tree matching the name “src”:
find . -type d -name src- Use
-type fto search only files, or-type lto only search symbolic links. -nameis case sensitive. use-inameto perform a case-insensitive search.
which — command will return the path to the command specified
which <command> // returns the path its locatedFIle Comparison
md5sum — helps create, read, and check file checksums (compares intergrity of your download and the original version)
diff — compares two files and tell whats the difference
diff dogs.txt moredogs.txtNetwork
netstat — show network status and protocol statistic
telnet — create a remote connection with a system over a TCP/IP network
nslookup — retrieve information about a specific domain or IP address
ping — check if network host is reachable
File text manipulation
sort — helps you sort by name
- r -> reverses the order
- Sorting by default is case sensitive, and alphabetic. Use the
--ignore-caseoption to sort case insensitive, and the-noption to sort using a numeric order. - u — removes duplicate
grep — search in files, or combine it with pipes to filter the output of another command (grep -n <search text> <filename>)
- to allow the grep command to give you more context use this coomand
grep -nC 2 document.getElementById index.md // print 2 lines before and 2 lines after the matched linedate — Display the current date & time
$ datetree — Display the directory structure starting from the current directory
$treeOS / Process related commands:
ps — display information about all running processes
$ ps auxtop — display real time information about CPU & Memory usage
topdf — Display disk space usage of all mounted file systems
df -huname — Display system information such as kernel name version etc.
uname -afree — display memory usage statics
free -mlspci — list all PCI devices
lspcikill — terminate a process with PID “1234”
kill 1234Network Related commands:




