ls Lists a directory’s content
pwd Shows the current working directory’s path
cd Changes the working directory
mkdir Creates a new directory
rm Deletes a file
cp Copies files and directories, including their content
mv Moves or renames files and directories
touch Creates a new empty file
file Checks a file’s type
zip and unzip Creates and extracts a ZIP archive
tar 'tape archive', works with Archives
- c creates an archive by bundling files/directories together
- x extracts files and directories from an existing archive
- f specifies the filename of the archive to be created or extracted
- t displays or lists the files and directories contained within an archive
- u archives and adds new files or directories to an existing archive
- v displays verbose info, providing detailed output during the archiving or extraction process
- A concatenates multiple archive files into a single archive
- z uses gzip compression when creating a tar file, resulting in a compressed archive with the '.tar.gz' extension
- j uses bzip2 compression when creating a tar file, resulting in a compressed archive with the '.tar.bz2' extension
- W verifies the integrity of an archive file, ensuring its contents are not corrupted
- r updates or adds files or directories to an already existing archive without recreating the entire archive
-
- (참조: https://www.geeksforgeeks.org/tar-command-linux-examples/)
nano, vi, and jed Edits a file with a text editor
cat Lists, combines, and writes a file’s content as a standard output
grep Searches a string within a file
sed Finds, replaces, or deletes patterns in a file
head Displays a file’s first ten lines
tail Prints a file’s last ten lines
awk Finds and manipulates patterns in a file
sort Reorders a file’s content
cut Sections and prints lines from a file
diff Compares two files’ content and their differences
tee Prints command outputs in Terminal and a file
locate Finds files in a system’s database
find Outputs a file or folder’s location
sudo Runs a command as a superuser
su Runs programs in the current shell as another user
chmod Modifies a file’s read, write, and execute permissions
chown Changes a file, directory, or symbolic link’s ownership
useradd and userdel Creates and removes a user account
df Displays the system’s overall disk space usage
du Checks a file or directory’s storage consumption
top Displays running processes and the system’s resource usage
htop Works like top but with an interactive user interface
ps Creates a snapshot of all running processes
uname Prints information about your machine’s kernel, name, and hardware
hostname Shows your system’s hostname
time Calculates commands’ execution time
systemctl Manages system services
watch Runs another command continuously
jobs Displays a shell’s running processes with their statuses
kill Terminates a running process
shutdown Turns off or restarts the system
ping Checks the system’s network connectivity
wget Downloads files from a URL
curl Transmits data between servers using URLs
scp Securely copies files or directories to another system
rsync Synchronizes content between directories or machines
lfconfig Displays the system’s network interfaces and their configurations
netstat Shows the system’s network information, like routing and sockets
traceroute Tracks a packet’s hops to its destination
nslookup Queries a domain’s IP address and vice versa
dig Displays DNS information, including record types
history Lists previously run commands
man Shows a command’s manual
echo Prints a message as a standard output
ln Links files or directories
alias and unalias Sets and removes an alias for a file or command
cal Displays a calendar in Terminal
apt-get Manages Debian-based distros package libraries
연산자
&: Ampersand Operator
- By appending the ampersand operator to any command, you dictate the shell to execute that Linux command in the background so that you can continue using the shell untethered.
; Semicolon Operator
- The semicolon operator is an incredibly useful Linux chaining operator that you can use to execute commands in a defined, sequential order. Order your commands and separate them by semicolons.
- 예) pwd ; mkdir test ; cd test ; touch file
- The above syntax dictates the shell to execute each command one after the other. Note that the shell does not check if each command terminates successfully. As soon as the shell receives a return code, it moves on to executing the next command.
||: or
- The OR operator will execute the command that follows only if the preceding command fails, i.e., returns an exit code of 0. It functions like a logical OR gate, which returns a value of 1 when the input is 0.
- 예) bad_command || ls
- In this example syntax, bad_command is a false command that will fail to execute and since it fails, the command succeeding the OR operator, which is the ls command, will execute successfully.
|: pipe
- The pipe operator directs the output of the preceding command as input to the succeeding command. It is most commonly used to filter data with the grep command.
- 예) cat test | grep -i "makeuseof"
- This command sends the output of the cat command as input to the grep command, which then filters the output against a specified string.
&&: and
- This operator functions in similar ways to the semicolon operator except, unlike the semicolon operator, AND operator will execute commands only if the preceding command was successfully executed.
- 예) pwd && mkdir test && cd test && bad_command && ls
- In this example syntax, the shell will successfully execute all the commands up until bad_command. However, since bad_command fails to run, the shell will return an error and skip the ls command.
!: not
- The NOT operator works in similar ways to an except statement in programming. For instance, if you want to perform an operation on a large number of files in a directory but want to exclude a few based on some parameter, then you can use the NOT operator by passing the parameter after the NOT character (!).
- 예) rm -r !(*.txt)
- This sample command will recursively remove all files in a directory except for files that have a ".txt" extension.
{..}: Combination
- As the name hints, the combination operator is used to group commands. Whichever commands you want to group you can place them inside curly brackets, and they will be executed depending upon the exit code of the first command.
- 예) test -f /etc/passwd && {pwd ; date} && echo $0 ; echo "Hello"
- The sample syntax will test if the /etc/passwd file is present, print the current working directory, date, shell name, and echo "Hello".
\: Concatenation or the Escape
- The concatenation or escape operator has two functions. You can either use it to concatenate two commands or as an escape character when working with strings in the shell.
- 예) mkdir test0 test1 \ test2
echo "Hello! from the \nother side"
- The first command will make four directories named test0 through test2, and the second command will print the string separated by a new line.
>, >>, <: redirection
- The redirection operators redirect output or input to a file either by re-writing the file or by appending to it. If you want to re-write a file, then you have to use the single angle bracket (>) syntax. If you want to append to a file, you'll have to use the double angle bracket syntax (>>).
- 예) echo "dsd" > test ; echo "bssss" >> test
- In the sample syntax, the first command will overwrite the "test" file with the provided string but, in the second command, the string provided will be appended to the test file.
참조
'OS 운영체제 > LINUX' 카테고리의 다른 글
grep (패턴 맞춤 출력 명령) (0) | 2024.10.17 |
---|---|
awk (텍스트 조작 명령어) (0) | 2024.09.20 |
sed (텍스트 편집 명령어) (1) | 2024.06.12 |
basename (파일 이름 명령어) (0) | 2024.06.05 |
readlink (심볼릭 파일 경로 읽는 명령어) (0) | 2024.06.05 |