Sitemap
Mustansirraza

Mustansirraza

Basic Linux Commands

4 min readMar 29, 2024

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_directory

mkdir -p — make multiple nested folders (mkdir -p fruits/apple)

$ mkdir -p my_directory/one

rmdir — removes an empty directory. (use rm -r to remove not empty directory)

$ rm -r file name

Basic File Operations

ls — list the directory contents.

 ls

pwd — tells the path of the directory you are in

 pwd

tree- list out all the directories and files in a tree like format

 tree directory name

cp -> copy files and directories (To copy a folder use -r along with cp)

 cp -r source direcotry to destination directory

mv — move (rename ) files. ex-> mv myname yourname (rename)

 mv file.txt

ln — Used to create links, its like a pointer to another file.

FIle Viewing

less — shows the content stored in a file.

 less large_file.txt

tail — watches for file changes by opening the file at the end

 tail file

cat — prints a file’s content to the standard output:

cat -n file1 // prints along with the number of lines

touch — 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.txt

chown — 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 it

df- 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 within

sudo — update package list using “apt”with super user privileges

 sudo apt update

apt — install a package named “package-name”.

 sudo apt install package-name 

touch — create a new file named “newfile.txt”

touch newfile.txt

cat — Display the content of a file name “file.txt”

cat file.txt

less — view the content of a large file name “large_file.txt”

less large_file.txt

more — view the content of a file named “file.txt” page by page

more file.txt

rsync — synchronize the contents of two directories “source-directory” and “destination-directory”

 rsync

File 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 .js extension 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 f to search only files, or -type l to only search symbolic links.
  • -name is case sensitive. use -iname to perform a case-insensitive search.

which — command will return the path to the command specified

which <command> // returns the path its located

FIle 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.txt

Network

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-case option to sort case insensitive, and the -n option 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 line

date — Display the current date & time

$ date

tree — Display the directory structure starting from the current directory

$tree

OS / Process related commands:

ps — display information about all running processes

$ ps aux

top — display real time information about CPU & Memory usage

top

df — Display disk space usage of all mounted file systems

df -h

uname — Display system information such as kernel name version etc.

uname -a

free — display memory usage statics

free -m

lspci — list all PCI devices

lspci

kill — terminate a process with PID “1234”

kill 1234

Network Related commands:

--

--