Table of contents
No headings in the article.
First check whether you are root user or just a user.
If you are user, than follow the commands
[User..........~]$ sudo su
[root........user]# cd
[root.......~] to change to different user than
[ root...~] cd /home/ec2-user/
[root.....user].. Now execute all commands
Command | Description | commands |
cd | change directory. | cd |
cd - or cd .. | moves to the previous directory. | cd - or cd .. |
cd ~ | takes you back to the home directory. | cd ~ |
ls | list directory contents. | ls |
ls -a | lists all the files including hidden files. | |
ls -x | lists the content in row-wise format. | |
ls -r | lists the contents sorted in reverse alphabetical order. | |
ls -t | lists the directory contents sorted by last creation time. | |
ls -s | to list the file size | |
ls -R | lists all subdirectories under a current directory. | |
ls -l | displays all files & directories in long format. | |
ls -u | lists the contents based on access time or usage time. | |
ls -A | list almost all include hidden files . except . and .. | |
ls -F | to display all the file by type dir file _ / executable file _ \ , link file* _ @ | |
ls -f | to disable colors | |
ls [abc]* | lists all the files starting with the letter a/b/c. | |
ls [!abc]* | lists all the files that don't start with the letter a/b/c. | |
ls / | root directory contents will be displayed. | |
ls ../ | displays the content of the parent directory. | |
ls */ | lists the contents of all subdirectories of the current directory. | |
ls -d* | displays all directories followed by filenames. | |
touch | creates an empty file. or change the time stamp | touch filename |
touch -a | changes the access time of a file. | |
touch -m | changes the modification time of a file. | |
moving & renaming | ||
mv | used to move or rename files and directories. | mv oldname newname |
mv -f | forces overwriting of the target file. | |
mv -i | prompts before overwriting the destination file. | |
mv -p | preserves the attributes from 1 file to another file. | |
rm | removing or deleting 1 or more files. | rm filename |
rm -i | prompts before deleting each file. i means intimate | |
rm -r | recursively delete a directory and all its contents. | |
rm -rf | to remove file or dir with forcefully without get any error | |
rmdir | to remove the directory only | |
rm -rv | to know the sequence of deleting file or dir | |
uname | shows the name and certain features of the system. | |
uname -r | displays OS release details. | |
uname -m | displays machine details. | |
uname -v | displays version details. | |
cp -i ,-v | copy file or a group of files across directories. | cp sourcefile destinationfile |
copy all files of dir1 will be copied in dir2 | cp dir1/* dir2 | |
pwd | prints current working directory. | |
mkdir | to make directory | |
rmdir | removes the directory. | |
echo | displays messages. | |
cat | used to concatenate and display files. | -n(num),-b(blank) |
to create a file |
| |
to view file |
| |
to append the data in a existing file |
| |
whoami | gives self-login details. | |
sudo | lets us use our account and password to execute system commands with root privileges. | |
tree | to list the content of directories and files in tree format |
if we want to create a directory within directory at once then -
mkdir –p DevOps/Linux/ShellScriptin/Git/Maven/Tomcat
use this when you write custom permission -
mkdir –m 700 python
(with the file permission)
Inode : Inode is a Data Structure, stores the file/dir info
chmod(symbolic codes) | |||
u /g /o /a users/group/others/all | r / w / x (read/write/execute) | + / - / = add/remove/assign | change the access permissions on a file. |
chmod u/g/o/a file.txt | chmod u/g/o/a+r file.txt | added read permission to file.txt | |
chmod u/g/o/a+w file.txt | added write permission to file.txt | ||
chmod u/g/o/a+x file.txt | added execute permission to file.txt. | ||
chmod u/g/o/a+rwx file.txt | added all permissions at once to file.txt | ||
chmod (numeric, octal representation) | |||
Octal numbers | Binary value & text equivalent | Example | Description |
binary equivalent (r,w,x) for (owner, group, and others) | |||
0 | 000 _ | chmod 000 file.txt | all types of access are denied. |
1 | 001 x | chmod 111 file.txt | execute access is allowed to u+g+o. |
2 | 010 w | chmod 222 file.txt | write access is allowed to u+g+o. |
3 | 011 _ w x | chmod 333 file.txt | write and execute access is allowed to u+g+o. |
4 | 100 r | chmod 444 file.txt | read access is allowed to u+g+o. |
5 | 101 r _ x | chmod 555 file.txt | read & execute access is allowed to u+g+o. |
6 | 110 r w _ | chmod 666 file.txt | read & write access is allowed to u+g+o. |
7 | 111 r w x | chmod 777 file.txt | all types of access are allowed to u+g+o. |
Some Other examples | |||
command | Description | Command | Description |
chgrp | to change group name | chgrp demo.txt root | domo.txt belongs to root group |
chown | to change owner | chown root demo.txt | now owner of demo.txt is root |
_ if in case it shows username or group name is invalid then add sudo adduser <name>
umask :
Means user mask. hiding permissions
It is going to set default permissions to file/directory
first is sticky bit mostly used in admin related activities