ls command
The ls
command is used in Linux and Unix-based operating systems to list files and directories in a directory. Here are some commonly used options with the ls
command:
ls
- to show content inside a directoryls -a
: list hidden files also with other filesls -l
: list content with long detailsls -R
: also shows content available in sub directory
cd command
The cd
command is used in Linux and Unix-based operating systems to change the current working directory. It allows you to navigate through the file system and access different directories.
cd
: Without any arguments, thecd
command takes you to your home directory.cd <directory>
: Changes the current directory to the specified directory. For example,cd Documents
moves you to the "Documents" directory if it exists in the current directory.cd ..
: Moves up one level in the directory hierarchy. For example, if you're in the "Documents" directory,cd ..
will take you back to the parent directory.cd /
: Takes you to the root directory.cd ~
: Takes you to your home directory.cd -
: Takes you to the previous directory you were in.
mkdir command
The mkdir
command is used in Linux and Unix-based operating systems to create directories (folders). It allows you to create one or multiple directories at a time.
mkdir
- to make directorymkdir folder1/folder2
- creates folder 2 inside folder 1 if the folder 1 exists in current directorymkdir -p folder1/folder2
- p flag to create parent directories as needed
cat command
The cat
command is used in Linux and Unix-based operating systems to concatenate and display the contents of files. It is also frequently used to create new files or append to existing ones
cat name.txt
- list all the things available in the text filecat > Hello
- creates a hello file and we can write content into itcat file1.txt > file2.txt
- copies the content of file 1 into file 2cat file1.txt file2.txt
- print file 1 then file 2cat file1.txt | tr a-z A-Z > upper.txt
- convert content of file 1 into uppercase using tr (translate) command and then saving into upper.txt
find command
The find
command is used in Linux and Unix-based operating systems to search for files and directories within a specified directory hierarchy.
find .
- find files in current directoryfind . -type d
- find the directories only inside current folderfind . -type f
- find files onlyfind . -type f -name "two*"
- find files that start with two ex - two.txt two.exefind . -type f -iname "two*"
- not case sensitivefind . -type f -mmin -20
- shows file modified less than 20 mins agofind . -type f -mmin +15
- shows file modified more than 15 mins agofind . -type f -mmin +2 --mmin -10
- modified more than 2 mins and less than 10 mins ago
-mtime - modified time in daysfind . -type f -maxdepth 1
- max depth 1 means in current directory but not in sub-directoryfind . -type f -size +1k
- search by sizefind . -perm 777
- find files by permission, 777 means read-write-executable
chmod command
Used to change permissions of file and directories
chmod u=rwx,g=rw,o=r uppertxt
- change file permission to read,write,exec for user, read,write for group, and read for otherschmod 777 upper.txt
- using octal numbers for read,write,execute for all threechown
- used to change ownership of files and directorieschown root upper.txt
- error thrown as it requires sudo aslosudo chown root upper.txt
- now the file upper.txt is only accesible to root user which is provided by sudo command.
Other commands
touch
touch text.txt
- used to create filestouch folder3/hello.txt
- create hello file inside folder3
cp
cp file.txt copyfile.txt
- create a copy a filecp -R folder1 folder2
- create copy of folder1 and entire subtree in folder2 and runs even if error occurs.
mv
mv name.txt random
- moves name file into random named foldermv file1.txt file2.txt
- file1 was removed and file 2 was created
rm
rm copyfile.txt
- permanently deletes/removes the file onlyrm -R copiedFolder
- R flag to specify to delete the folder
df
df
- display info about the disk space usage in kbdf -m
: m flag to display info in mbdf -g
: to display in gbdf -h
: to display in human-readable format
head
head
- display first few lines of filehead file.txt
- display few no of lines decided by systemhead -n 4 file.txt
- n flag to change the number of line to display to 4
Similarly we have tail command which just do the opposite of head command.
history
histor
y - list history of commands we usedhistory | grep "ls"
-list of ls commands we used!2742
- id of one of our previous command, doing this will run this command from the history
zip
zip
- to compress files and directories into a zip archivezip
files.zip
companies.txt
- zip companies fileunzip
files.zip
- to unzip files
User related
useradd User
- to add new userpasswd User
- to set passworduserdel User
- deletes a user names User
Info
To know more about a particular command just write <command name> --help
you will get more possible things that we can do using a command.
Operations -
& - creates a background on which some commands run so that others don't get blocked
&& - only when lhs in successful then only rhs will run
| - send output in first command in the second command
|| - if lhs get executed then it's print otherwise rhs will then run
! - not operator to reverse the logic output
rm -rf !(name.txt) - remove file except names.txt
\>> - used to append data not overwrite it
{} - combination operator used to group the commands
Best things to do with these commands is not to memorize them but play with them whenever you are dealing with terminal.
Follow -
Comment below for suggestions and improvement :) Follow me for more such content ๐. If you have any doubts you can message me, and I will respond asap :)