Special Files in Linux
. Current directory
.. Parent directory
../ Parent directory, including slash; used to navigate from the parent
../../ The parent of the parent directory
~/ The current user’s home directory
.hiddenfile Files that start with a dot are hidden files. They are generally configuration files
Wildcards
? Represents any one character
* Represents any set of characters
[xbc] Represents any one of the characters listed within the bracket
[a-z] Represents any character between the defined range
History
View and edit commands previously run
~/.bash_history: Location of your Bash history
CTL + R: Searches the history of commands
history: Shows a list of commands that have been previously run in a numbered list
!
I/O
I/O stands for Input / Output.
STDOUT: Standard output of command line programs
STDIN: The source of input(s) for a program
STDERR: Standard error output of a command line program
Redirection
These redirect the output or input of a command into files, devices, and the input of other commands.
> Redirects the standard output of a command into a file; replaces the contents of a file
>> Appends into the end of a file
< Imports the contents of a file into the command
<< Appends the contents of a file into the command
2> Redirects standard error of a command into a file
2>> Appends standard error of a command into the end of a file
&> Redirects standard error and standard output when redirecting text
&>> Appends standard error and standard output when redirecting text
Example: cat < test.txt >> existingfile.txt
Uses the contents of test.txt on the cat command, then appends the results to existingfile.txt
Piping
This processes commands on the output of other commands
Uses the standard output of a command prior to the pipe as the standard input for the command following the pipe
Options:
; Run the following command even if the previous command fails or succeeds
&& Run the following command only if the previous succeeds or has no errors
|| Run the following command only if the previous fails or results in error
& Run the previous command in the background
Command Substitution
Inserts command output into another context
`Back Ticks` Input any bash command or set of commands
$(Dollar Sign & Parenthesis) Input any bash command or set of commands
Examples:
`echo the current date is `date` Outputs the current date at the end of the string
file $(which login) Outputs the file type of the located command file
echo "$(users | wc -w) users are logged in right now" Outputs users are logged in right now
Jobs
Commands run from the terminal, whether in the foreground or in the background
In the terminal, while running a command, you can use CTRL+Z to stop, but not kill, a command/job. You can start it up again later, either in the foreground or background.
jobs Shows jobs and commands running in the background
fg <job_number>
Environment Variables
env Shows all environment variables
env | grep EXAMPLE Prints current environment variables and then greps the result for the term EXAMPLE export EXAMPLE=VAR Exports shell variable EXAMPLE to the environment variables EXAMPLE=VAR ; export EXAMPLE Exports a previously-defined shell variable to the environment variables After you log off, the environment variables you set will restore to default. To permanently set an environment variable, you must either edit the user configuration files or global configuration files for Bash.
Add to .bashrc (for user):
ABC="123"; export ABC
Add to /etc/.bash.bashrc (for system):
ABC="123"; export ABC
Linux Commands:-
useradd: Command that's used to create a local user account
usermod: Command that's used to modify a local user account
userdel: Command that's used to delete a local user account
groupadd: Command that's used to create a local group
groupmod: Command that's used to modify a local group
groupdel: Command that's used to delete a local group
passwd: Command that's most often used to assign passwords to user accounts, but it can be used for some other scenarios (for example, locking user accounts)
chage: Command that's used to manage user password expiry.
Directory | Usage |
---|---|
/ | Root of the virtual directory, where normally, no files are placed |
/bin | Binary directory, where many GNU user-level utilities are stored |
/boot | Boot directory, where boot files are stored |
/dev | Device directory, where Linux creates device nodes |
/etc | System configuration files directory |
/home | Home directory, where Linux creates user directories, which are optional |
/lib | Library directory, where system and application library files are stored |
/libname | Library directory(ies), where alternative format system and application library files are stored, which is optional |
/media | Media directory, a common place for mount points used for removable media |
/mnt | Mount directory, a common place used for temporarily mounting filesystems |
/opt | Optional directory, where third-party software packages are stored |
/proc | Process directory, where current kernel, system, and process information is stored |
/root | Root user's home directory, which is optional |
/run | Run directory, where runtime data is held during system operation |
/sbin | System binary directory, where many GNU admin-level utilities are stored |
/srv | Service directory, where local services store their files |
/sys | System directory, where devices, drivers, and some kernel feature information is stored |
/tmp | Temporary directory, where temporary work files can be created and destroyed |
/usr | User directory, a secondary directory hierarchy |
/var | Variable directory, for files that change frequently, such as log files |
- A question mark (
?
) to represent one character - An asterisk (
*
) to represent any number of characters
0 Comments