Commands that are entered at the shell prompt have three basic parts:
- Command to run
- Options to adjust the behavior of the command.
- Arguments, which are typically targets of the command.
The command is the name of the program to run. It might be followed by one or more options, which adjust the behavior of the command or what it will do. Options normally start with one or two dashes (-a or --all, for example) to distinguish them from arguments. Commands might also be followed by one or more arguments, which often indicate a target that the command should operate on.
For example, in the usermod -L user01 string, usermod is the command, -L is the option, and user01 is the argument. This command locks the password of the user01 user account.
Using the (+) as an argument to specify a format string for the date command.
date +%R
date +%x date --help
passwd
The passwd command with no options changes the current user's password. To change the password, first specify the original password for the account. By default, the passwd command is configured to require a strong password, to consist of lowercase letters, uppercase letters, numbers, and symbols, and not based on a dictionary word. A superuser or privileged user can use the passwd command to change another user's password.
cat
The cat command is one of the most simple and frequently used commands in Linux. Use this command to create single or multiple files, view the contents of files, concatenate the contents from various files, and redirect contents of the file to a terminal or to files
file /etc/passwd
Shortcut | Description |
---|---|
Ctrl+A | Jump to the beginning of the command line. |
Ctrl+E | Jump to the end of the command line. |
Ctrl+U | Clear from the cursor to the beginning of the command line. |
Ctrl+K | Clear from the cursor to the end of the command line. |
Ctrl+LeftArrow | Jump to the beginning of the previous word on the command line. |
Ctrl+RightArrow | Jump to the end of the next word on the command line. |
Ctrl+R | Search the history list of commands for a pattern. |
- What is an absolute path?
- Where does an absolute path begin?
- What is a relative path?
pwd - displays full path name of current directory
The touch command updates the time stamp of a file to the current date and time without otherwise modifying it. This command is useful for creating empty files, which can be used for practice, because when you use the touch command with a file name that does not exist, the file is created
ls - lists the directory contents for the specified directory, or if no directory is given, for the current working directory.
- ls command has multiple options for displaying attributes on files. The most common options are -l (long lisitng format), -a(all files, including hidden files), and -R(recursive, to include the contents of all subdirectiories).
Files names that begin with a dot (.) indicate hidden files; you cannot see them in the normal view ls and other commands. This behavior is not a security feature. Hidden files keep necessary user configuration files from cluttering home directories.
cd - command to change your shell's current working directory. If you don't specify any arguments to the command, then it changes to your home directory.
- cd command has many options. Some are useful to practice early and use often. THe cd - command changes to the previous directory; where the user was previously to the current directory.
- cd .. command uses the (..) hidden directory to move up one level to the parent directory, without needing to know the exact parent name. The other hidden directory (.) soecifies the current directory on commands where the current location is either the source or destination argument, and avoids the need to type the directory's absolute path name.
Be aware of the options that are used in a commend THe meaning of some options might differ between commands.
mkdir - creates one or more directories or subdirectories. It takes as an argument a list of paths to the directories that you want to create.
Use the mkdir command and a space-delimited list of the directory names to create multiple directories.
If the directory exists, or a parent directory of the directory that you are trying to create does not existm then mkdir command fails and it displays an error.
The mkdir command -p(parent) option creates any missing parent directories for the requested destination.
The cp command copies a file, and creates a file either in the current directory or in a different specified directory.
You can also use the cp command to copy multiple files to a directory.
By default, the cp command does not copy directories; it ignores them.
Use the mv command to rename a file. Use the mv command to move a file to a different directory.
The rm command removes files, By default, rm does not remove directories. You can use the rm command -r or -- recursive option to enable the rm command to delete directories and their contents. The rm - r command traverses each subdirectory first, and individually removes their files before removing each directory.