Linux - 2

Linux - 2

Basic Linux commands & file Permissions

·

6 min read

Table of contents

No heading

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

CommandDescriptioncommands
cdchange directory.cd
cd - or cd ..moves to the previous directory.cd - or cd ..
cd ~takes you back to the home directory.cd ~
lslist directory contents.ls
ls -alists all the files including hidden files.
ls -xlists the content in row-wise format.
ls -rlists the contents sorted in reverse alphabetical order.
ls -tlists the directory contents sorted by last creation time.
ls -sto list the file size
ls -Rlists all subdirectories under a current directory.
ls -ldisplays all files & directories in long format.
ls -ulists the contents based on access time or usage time.
ls -Alist almost all include hidden files . except . and ..
ls -Fto display all the file by type dir file _ / executable file _ \ , link file* _ @
ls -fto 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.
touchcreates an empty file. or change the time stamptouch filename
touch -achanges the access time of a file.
touch -mchanges the modification time of a file.
moving & renaming
mvused to move or rename files and directories.mv oldname newname
mv -fforces overwriting of the target file.
mv -iprompts before overwriting the destination file.
mv -ppreserves the attributes from 1 file to another file.
rmremoving or deleting 1 or more files.rm filename
rm -iprompts before deleting each file. i means intimate
rm -rrecursively delete a directory and all its contents.
rm -rfto remove file or dir with forcefully without get any error
rmdirto remove the directory only
rm -rvto know the sequence of deleting file or dir
unameshows the name and certain features of the system.
uname -rdisplays OS release details.
uname -mdisplays machine details.
uname -vdisplays version details.
cp -i ,-vcopy file or a group of files across directories.cp sourcefile destinationfile
copy all files of dir1 will be copied in dir2cp dir1/* dir2
pwdprints current working directory.
mkdirto make directory

rmdir

removes the directory.

echo

displays messages.

cat

used to concatenate and display files.

-n(num),-b(blank)

to create a file

cat > filename

to view file

cat < file name or cat file name

to append the data in a existing file

cat > file name

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

  1. if we want to create a directory within directory at once then -

    mkdir –p DevOps/Linux/ShellScriptin/Git/Maven/Tomcat

  2. 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/allr / w / x (read/write/execute)+ / - / = add/remove/assignchange the access permissions on a file.
chmod u/g/o/a file.txtchmod u/g/o/a+r file.txtadded read permission to file.txt
chmod u/g/o/a+w file.txtadded write permission to file.txt
chmod u/g/o/a+x file.txtadded execute permission to file.txt.
chmod u/g/o/a+rwx file.txtadded all permissions at once to file.txt
chmod (numeric, octal representation)
Octal numbersBinary value & text equivalentExampleDescription
binary equivalent (r,w,x) for (owner, group, and others)
0000 _chmod 000 file.txtall types of access are denied.
1001 xchmod 111 file.txtexecute access is allowed to u+g+o.
2010 wchmod 222 file.txtwrite access is allowed to u+g+o.
3011 _ w xchmod 333 file.txtwrite and execute access is allowed to u+g+o.
4100 rchmod 444 file.txtread access is allowed to u+g+o.
5101 r _ xchmod 555 file.txtread & execute access is allowed to u+g+o.
6110 r w _chmod 666 file.txtread & write access is allowed to u+g+o.
7111 r w xchmod 777 file.txtall types of access are allowed to u+g+o.
Some Other examples
commandDescriptionCommandDescription
chgrpto change group namechgrp demo.txt rootdomo.txt belongs to root group
chownto change ownerchown root demo.txtnow 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