English Posting

simple Linux command

지식루프 2024. 6. 8. 16:10
728x90
반응형

The operating system used on EC2 servers in AWS is Linux.

Linux is an operating system derived from UNIX, and its commands are almost identical to UNIX.

Here, you will encounter the term "Unix Shell." The Unix Shell provides a user interface for the Unix operating system and Unix-like systems.

Unix allows you to control the computer by executing the shell with string inputs.

The basic commands of Unix are as follows:

  1. ls (list)
    • Lists the files and directories in a directory.
    • By default, it shows the files and directories in the current location, but it does not show hidden folders or files.
    • Therefore, you need to add options to the command to see them.
    Examples:
    • -l: Displays the list with detailed information >> ls -l
    • -a: Lists all files, including hidden ones >> ls -al
    • -F: Appends a character to the end of each name to indicate the type of file. For example:
      • /: Indicates a directory
      • *: Indicates an executable file
    ls -alF





  2. cd (change directory)
    • Changes the current working directory.
    • Example: cd /home/user (Moves to the user's home directory)
    To move to the parent directory, type cd .. (two dots). . (one dot) represents the current location, and .. (two dots) represents the parent directory.

  3. pwd (print working directory)
    • Prints the path of the current working directory.
    • Example: pwd
  4. cp (copy)
    • Copies files or directories.
    • Example: cp source.txt destination.txt (Copies source.txt to destination.txt)
    For instance, executing cp test1.txt test2.txt copies test1.txt to test2.txt. Note that if there is already a file named test2.txt, it will be overwritten, so use this command cautiously. To copy an entire directory, use the -r option.
    To prevent overwriting, use the -i option.



  5. mv (move)
    • Moves or renames files or directories.
    • Example: mv oldname.txt newname.txt (Renames oldname.txt to newname.txt)
    If the target is a directory, the mv command moves the first target to that directory. If the directory does not exist, it interprets the command as renaming the file.

  6. rm (remove)
    • Deletes files.
    • Example: rm filename.txt (Deletes the file named filename.txt)
    To delete a directory, use the -r option: rm -r directory (Deletes the directory regardless of whether it is empty). Be cautious when using this command, as it deletes without any warning, and the deleted files or directories cannot be recovered.

  7. mkdir (make directory)
    • Creates a new directory.
    • Example: mkdir newdirectory
  8. rmdir (remove directory)
    • Deletes an empty directory.
    • Example: rmdir directory
    If the directory is not empty, it cannot be deleted. Therefore, the rm -r command is more frequently used than rmdir.

  9. touch
    • Changes the file's creation and modification time or creates a new empty file.
    • Example: touch newfile.txt (Creates a file named newfile.txt)
  10. cat (concatenate)
    • Displays or concatenates the contents of files.
    • Example: cat file.txt (Displays the contents of file.txt)
  11. echo
    • Prints the given string.
    • Example: echo Hello, World!
  12. man (manual)
    • Displays the manual page for a command.
    • Example: man ls (Displays the manual page for the ls command)
  13. grep
    • Searches for a specific string within a file.
    • Example: grep "searchstring" filename.txt (Searches for "searchstring" in filename.txt)
  14. find
    • Finds files or directories in the file system.
    • Example: find / -name "filename.txt" (Finds "filename.txt" in the root directory)
  15. chmod (change mode)
    • Changes the permissions of a file or directory.
    • Example: chmod 755 filename.txt (Sets the permissions of filename.txt to 755)
  16. chown (change owner)
    • Changes the owner and group of a file or directory.
    • Example: chown user:group filename.txt (Changes the owner of filename.txt to user and the group to group)
  17. ps (process status)
    • Displays the currently running processes.
    • Example: ps -ef (Displays detailed information of all processes)
  18. kill
    • Terminates a process.
    • Example: kill 1234 (Terminates the process with process ID 1234)
  19. top
    • Displays real-time system processes and resource usage.
    • Example: top
  20. df (disk free)
    • Shows the disk usage of the file system.
    • Example: df -h (Displays the disk usage in a human-readable format)
  21. du (disk usage)
    • Summarizes the disk usage of a specific directory.
    • Example: du -sh /home/user (Displays the total disk usage of the user's home directory)

These commands are frequently used in Unix systems, and each command offers various options for different uses. For more detailed information about a command, you can refer to the manual page using the man command.

728x90
반응형