Anzeige
Anzeige

Más contenido relacionado

Anzeige

Linux Command.pptx

  1. Linux Command By Vineeta
  2. LINUX COMMAND man: man command in Linux is used to display the user manual of any command that we can run on the terminal. It provides a detailed view of the command which includes NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS and SEE ALSO.
  3. COMMAND : man ls
  4. pwd : Print Work Directory pwd stands for Print Working Directory. It prints the path of the working directory, starting from the root.
  5. To check the version of pwd Command : /bin/pwd --version
  6. cal command This command display the calendar of current month.
  7. ncal Comand : ncal
  8. Command: cal -m1 , cal -m2 , cal -m3 ...
  9. Command: cal -y year / cal -y 2020
  10. date Command : date Displays current time and date.
  11. whoami Command : whoami This command reveals the user who is currently logged in.
  12. whatis Command : whatis ls / whatis date This command gives a one line description about the command. It can be used as a quick reference for any command.
  13. w Command : w The w command lists the currently logged in users.
  14. id Command: id / id (root) by passing username as argument This command prints user and groups (UID and GID) of the current user.
  15. UID : User Identifier A UID (user identifier) is a number assigned by Linux to each user on the system. This number is used to identify the user to the system and to determine which system resources the user can access. ● UID 0 (zero) is reserved for the root. ● UIDs 1–99 are reserved for other predefined accounts. ● UID 100–999 are reserved by system for administrative and system accounts/groups. ● UID 1000–10000 are occupied by applications account. ● UID 10000+ are used for user accounts.
  16. GID : Group Id Groups in Linux are defined by GIDs (group IDs). ● GID 0 (zero) is reserved for the root group. ● GID 1–99 are reserved for the system and application use. ● GID 100+ allocated for the user’s group.
  17. clear This command clears the screen Command : clear Shortcut : ctrl+L
  18. ps The ps command lists running processes. Using ps without any options causes it to list the processes running in the current shell. Command : ps
  19. history The history command lists the commands you have previously issued on the command line. You can repeat any of the commands from your history by typing an exclamation point ! and the number of the command from the history list Command : history
  20. mkdir The mkdir command allows you to create new directories in the filesystem. You must provide the name of the new directory to mkdir. If the new directory is not going to be within the current directory, you must provide the path to the new directory. Command : mkdir os / mkdir os cpp ds
  21. Linux version Uname to check the version of linux.
  22. -v 0r --verbose It displays a message for every directory created. Command: mkdir -v 1 2 3
  23. -p A flag which enables the command to create parent directories as necessary. If the directories exist, no error is specified. Command: mkdir -p dss/ds/d
  24. To create files Create a file with touch command We will use touch command with any extension to create file, this command will create an empty file test.txt in your current directory Command : touch file.txt
  25. Create a file with cat command cat command to create file, this command will create an empty file in your current directory, but you must add text in the file. Command: cat > testcat.txt This file has been created with cat command To save the file hit Ctrl + d and to check whether it is present in your directory or not Command : ls -l testcat.txt
  26. Create a file with echo command echo command to create file, this command will create a file in the current directory but you should add text in the line command. Command : echo "check echo" > testecho.txt To see the file,type command below. Command: ls -l testecho.txt
  27. Create a file with printf command We will use printf command to create file, this command will create a file printf.txt in your current directory as an example below, but you should add text in the line command. Command: printf "This file has been created with printf command" > printf.txt To see the file type command below. Command: ls -l printf.txt
  28. Create a file using nano To create a file using nano text editor, first install it, after that type command below and the text editor will be opened to adding text. Command : nano nano.txt Add the text below. This file has been created with nano text editor To save the file type Ctrl + x and type y, to see the file type command below. Command: ls -l nano.txt
  29. Create a file with vi editor To create a file using vi text editor, type command below and the text editor will open the file, but you can't add any text before converting it to insert mode by typing i character. Command: vi vi.txt Add the text below. This file has been created with vi text editor To save the file and exit hit Esc after that :wq, To see the file type command below. Command : ls -l vi.txt
  30. Create a file with vim text editor To create a file using vim text editor, type command below and the text editor will open the file, but you can't add any text before converting it to insert mode by typing i character. Command : vim vim.txt Add the text below. This file has been created with vim text editor To save the file and exit hit Esc after that :wq, to see the file type command below. Command : ls -l vim.txt
  31. How to remove a file To remove (or delete) a file in Linux from the command line, use either the rm (remove) or unlink command. To delete a single file, use the rm or unlink command followed by the file name: Command : unlink filename / rm filename
  32. To delete a file To delete multiple files at once, use the rm command followed by the file names separated by space. Command :rm filename1 filename2 filename3
  33. You can also use a wildcard (*) and regular expansions to match multiple files. For example, to remove all .pdf files in the current directory, use the following command: Command : rm *.pdf / rm *.txt
  34. ● Use the rm with the -i option to confirm each file before deleting it: Command : rm -i filename(s) ● To remove files without prompting even if the files are write-protected pass the -f (force) option to the rm command: Command : rm -f filename(s)
  35. rm -i filename
  36. Delete a empty directory use ‘-d‘ option in rm command to delete a empty directory. Command : rm -d appdata/
  37. You can also combine rm options. For example, to remove all .txt files in the current directory without a prompt in verbose mode, use the following command: Command: rm -fv *.txt
  38. How to remove directory In Linux, you can remove/delete directories with the rmdir and rm. rmdir is a command-line utility for deleting empty directories while with rm you can remove directories and their contents recursively.
  39. To remove an empty directory, use either rmdir or rm -d followed by the directory name: Command: rm -d dirname rmdir dirname
  40. -r‘ option in rm command will delete all the files and sub-directories recursively of the parent directory. rm -r dirname Delete the files and sub-directories interactively. Use ‘-ri‘ option in rm command to delete file and sub-directories interactively, Rm -ri dbstore To remove non-empty directories and all the files without being prompted, use rm with the -r (recursive) and -f options:rm -rf dirname
  41. To remove multiple directories at once, use the rm -r command followed by the directory names separated by space. Command : rm -r dirname1 dirname2 dirname3
  42. Delete large number files using rm command If your are trying to delete large number of files using rm command then you will get an error message ‘Argument list too long’ rm *.log
  43. Copy command Cp command is use to copy a file from source to destination Command :Cp target_file to source file
  44. Copy a file interactively If you wish to copy the files from one place to another interactively then use the “-i” option in cp command, interactive option only works if the destination directory already has the same file, example is shown below, Command : cp -i filename
  45. Copy a directory or folder (-r 0r -R) To copy a directory from one place to another use -r or -R option in cp command. Let’s assume we want to copy the home directory of linuxtechi user to “/mn/backup”, Command : cp -r /home/linuxtechi /mnt/backup/
  46. Do not overwrite the existing file while copying (-n) cp -n /etc/passwd /mnt/backup/
  47. Mv command move a file To move a file using the mv command pass the name of the file and then the new name for the file. In the following example the file foo.txt is renamed to bar.txt. mv foo.txt bar.txt
  48. Move a file into a directory To move a file into a directory using the mv command pass the name of the file and then the directory. In the following example the file foo.txt is moved into the directory bar. mv foo.txt bar
  49. How to move multiple file into a directory To move multiple files using the mv command pass the names of the files or a pattern followed by the destination. mv file1.txt file.2.txt file3.txt folder The following example is the same as above but uses pattern matching to move all files with a .txt extension. mv *.txt folder
  50. Move a directory To move a directory using the mv command pass the name of the directory to move followed by the destination. mv foo bar
  51. How to prompt before overwriting a file mv -i foo.txt bar.txt
  52. How to not overwrite an existing file To prevent an existing file from being overwritten pass the -n option mv -n foo.txt bar.txt
  53. How to take a backup of an existing file To take a backup of an existing file that will be overwritten as a result of the mv command pass the -b option. This will create a backup file with the tilde character appended to it. mv -b foo.txt bar.txt
  54. grep The grep utility searches for lines which contain a search pattern. When we looked at the alias command, we used grep to search through the output of another program, ps . The grep command can also search the contents of files. grep train *.txt
  55. gzip The gzip command compresses files. By default, it removes the original file and leaves you with the compressed version. To retain both the original and the compressed version, use the -k (keep) option. gzip -k core.c
  56. head head command gives you a listing of the first 10 lines of a file. If you want to see fewer or more lines, use the -n (number) option. In this example, we use head with its default of 10 lines. We then repeat the command asking for only five lines. Head -n 5 test.txt
  57. tail The tail command gives you a listing of the last 10 lines of a file. If you want to see fewer or more lines, use the -n (number) option. In this example, we use tail with its default of 10 lines. We then repeat the command asking for only five lines. tail core.c tail -n 5 core.c
  58. less The less command allows you to view files without opening an editor. It’s faster to use, and there’s no chance of you inadvertently modifying the file. With less you can scroll forward and backward through the file using the Up and Down Arrow keys, the PgUp and PgDn keys and the Home and End keys. Press the Q key to quit from less. To view a file provide its name to less as follows: less core.c
  59. ssh Use the ssh command to make a connection to a remote Linux computer and log into your account. To make a connection, you must provide your user name and the IP address or domain name of the remote computer. In this example, the user mary is logging into the computer at 192.168.4.23. ssh mary@192.168.4.23
  60. Cd command The cd command is used to change the current directory (i.e., the directory in which the user is currently working) in Linux
  61. Navigate to the Previous Directory To change back to the previous working directory, pass the dash (-) character as an argument to the cd command: cd -
  62. Navigate to the Home Directory To navigate to your home directory simply type cd. Another way to return directly to your home directory is to use the tilde (~) character, as shown below: cd ~
  63. Ls command Ls command shows the list of files and directories , where you won’t be able to view details like file types, size, modified date and time, permission and links etc. ls --version 1. A. ls -l shows file or directory, size, modified date and time, file or folder name and owner of file and its permission.
  64. ls > output.txt cat output.txt:
  65. 1. B. View Hidden Files: ls -a : contains the list of all the hidden file including “ .” and “. .” 1. C. List Files with Human Readable Format ls -lh : contains all the option which can be understood by non development person.
  66. 1. D. Sort Files by Files size ls -lS / ls -S -l: displays file size in order of bigger size first.
  67. ls -i : i over here is to check Inode Informations. An inode is a data structure that stores various information about a file in Linux, such as the access mode (read, write, execute permissions), ownership, file type, file size, group, number of links, etc. Each inode is identified by an integer number. An inode is assigned to a file when it is created.
  68. ls -R : You can list directories recursively using ls -R. Recursively means it will list all the directory with is all subdirectory in a tree format.
  69. ls -lt : Linux ls command with -t will list the files and directories by it’s modification date in ascending order, means the higher will be come first.
  70. ls ~ : command to list the contents in the user's home directory. ls -d */ command to list only directories: ls * command to list the contents of the directory with it's subdirectories ls -S (the S is uppercase) : command to list files or directories and sort by date or time in descending order (biggest to smallest). You can also add a -r flag to reverse the sorting order like so: ls -Sr
  71. ls -n: ls command with option -n will show the UID (User ID) and GID (Group ID) numbers of file and directory. A UID (user identifier) is a number assigned by Linux to each user on the system. This number is used to identify the user to the system and to determine which system resources the user can access. ● UID 0 (zero) is reserved for the root. ● UIDs 1–99 are reserved for other predefined accounts. ● UID 100–999 are reserved by system for administrative and system accounts/groups. ● UID 1000–10000 are occupied by applications account. ● UID 10000+ are used for user accounts.
  72. GID Groups in Linux are defined by GIDs (group IDs). ● GID 0 (zero) is reserved for the root group. ● GID 1–99 are reserved for the system and application use. ● GID 100+ allocated for the user’s group.
  73. ls -G If you want to list only Owner of the files and directories to which they are belongs and not groups then use Linux ls command with argument -G.
  74. There are three permissions groups: 1. Owner 2. Group 3. Other
  75. User: The owner of a file belongs to this class Group: The members of the file’s group belong to this class. A group is a collection of users. The main purpose of the groups is to define a set of privileges like read, write, or execute permission for a given resource that can be shared among the users within the group. Other: Any users that are not part of the user or group classes belong to this class.
  76. chown The chown command changes ownership of files and directories in a filesystem.
  77. To Change User ownership : To change user ownership we will use chown username file1.txt
  78. To reach to root
  79. Create new user
  80. To check list of user using compgen -u
  81. Changing the user Chown username filename
  82. To Change group ownership In our case I am using group1 as a group in the system. To change ownership we will use chown :group1 file1.txt
Anzeige