You are on page 1of 10

Linux Command ad Syntax

● File listing
○ Listing (alphabetical)
■ ls
○ long listing
■ ls -l
● - rw-r--r-- 1 prashant mithigateway 2839 May 8 15:52 test.txt
● <File Type> <Permissions> <No of Hard links> <User> <Group>
<Size> <Timestamp> <FileName>
● File Types

○ Alphabetical reverse listing


■ ls -lr
○ Listing according to timestamp
■ ls -lt
○ Listing according to reverse timestamp
■ ls -ltr
○ Sort by File size
■ ls -S
● Changing Directory
○ cd [options] [path]
○ Absolute Paths
■ An absolute path allows you to specify the exact location of a directory. It
always starts at the root directory, therefore it always begins with the /
character.
■ The path to the home directory /home/sysadminis an absolute path.
○ Relative Path
■ A relative path gives directions to a file relative to your current location in
the filesystem.
■ Relative paths do not start with the / character, they start with the name of
a directory.
○ The . Character
■ the . character always represents your current directory.
○ The ~ Character
■ The home directory of the current user is represented by the ~ character.
○ The .. Characters
■ .. always represents one directory higher relative to the current directory.
(Parent dir)
● Administrative Access
○ Su /su - /su -l/su --login
■ su OPTIONS USERNAME
■ The su command allows you to temporarily act as a different user. It does
this by creating a new shell.
■ The shell is simply a text input console that lets you type in commands.
By default, if a user account is not specified, the su command will open a
new shell as the root user, which provides administrative privileges.
○ Sudo
■ sudo [OPTIONS] COMMAND
■ The sudo command allows a user to execute a command as another user
without creating a new shell.
■ Execute the command as the root user by putting sudo in front of it.
■ The sudo command only provides administrative access for the execution
of the specified command.
● Permissions
○ Permissions determine the ways different users can interact with a file or
directory.
○ Permissions Field

■ Owner

■ Group
■ Other

● Permission Types
○ There are three different permissions that can be placed on a file or
directory: read, write, and execute.
● Changing File Permissions

○ The chmod command is used to change the permissions of a file or


directory. Only the root user or the user who owns the file is able to
change the permissions of a file.
○ There are two techniques for changing permissions with the chmod
command: symbolic and octal.
○ Symbolic : rwx
○ Octal : 4(read) + 2(write) + 1(execute) = 7
● Changing File Ownership
○ The owner of a file is the user who creates it.
○ The chown command is used to change the ownership of files and
directories.
○ Changing the user owner requires administrative access. A regular user
cannot use this command to change the user owner of a file, even to give
the ownership of one of their own files to another user.
○ chown [OPTIONS] [OWNER] FILE
● Copying Files
○ cp
○ dd
■ dd [OPTIONS] OPERAND
■ It can be used to clone or delete (wipe) entire disks or partitions.
■ It can be used to copy raw data to removable devices, such as
USB drives and CDROMs.
■ It can backup and restore the MBR (Master Boot Record).
■ It can be used to create a file of a specific size that is filled with
binary zeros, which can then be used as a swap file (virtual
memory).
● Filtering Input
○ grep [OPTIONS] PATTERN [FILE]
○ The grep command is a text filter that will search input and return lines
which contain a match to a given pattern.

○ Regular Expressions
● Viewing Processes
○ The ps command can be used to list processes.
■ ps [OPTIONS]
○ Running a command results in something called a process.
○ In the Linux operating system, processes are executed with the privileges of the
user who executes the command.

○ This allows for processes to be limited to certain capabilities based upon the user
identity.
● Password Management

● Vi Editor




○ Ex Mode

You might also like