반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

웹풀스택 공부 중

Bash 명령어 본문

웹개발/개발자

Bash 명령어

lukeit 2024. 8. 27. 09:54

📂 Directory Commands

  • pwd : Display the absolute path of the current directory.

  • cd (directory_name) : Change to the specified directory.

  • cd .. : Move up one directory (to the parent directory).

  • ls : List all files and directories in the current directory.

  • ls -la : Display detailed information for all files and directories, including hidden files (those that start with .).


🛠️ Directory & File Operations (Create, Move, Delete)

  • mkdir (directory_name) : Create a new directory.

  • rm (file_name) : Delete a file or directory.

  • rm -rf (directory_name) : Recursively force-delete a directory and its contents.

  • cp (source) (destination) : Copy files or directories from the source to the destination.

  • mv (source) (destination) or mv (old_name) (new_name) : Move a file (cut and paste) or rename a file.


📄 File Output

  • touch (file_name) : Create a new file.

  • cat (file_name) : Display the contents of a file.

  • echo 'txt_to_write' > (file_name) : Write text to a file (overwrite if it exists).

    • > : Overwrite the file.
    • >> : Append to the file.
  • echo : Can be used to view environment variable values, similar to Console.log.

  • export (ENVIRONMENT_VARIABLE)=(value) : Set an environment variable and use echo to confirm it.

    • This applies only to the session, so to save it, you can use vi ~/.bashrc to add the export command.
    • Save with :wq, then update with source ~/.bashrc to apply.
  • head -n 3 (file_name) : Display the first 3 lines of a file.

  • tail -n 3 (file_name) : Display the last 3 lines of a file.


🔄 Command Chaining

  • ls | sort | less : Pipe the output of the ls command into sort, and then pipe that result into less for viewing.

  • grep : Search for a specific pattern or regular expression in a string.


🔧 Other Command Modifiers

  • && : Perform independent commands (the output of one does not affect the next).

  • ; : Execute the next command even if the previous one fails.

  • & : Run the next command concurrently with the previous one.

  • || : Execute the next command only if the previous one fails.


🛠️ Utilities

  • chmod : Change file permissions.

    • Read (4), Write (2), Execute (1)

    • Example: 7 = Read + Write + Execute

    • Example: 1 = Execute only

    • First digit: Owner permissions.

    • Second digit: Group permissions.

    • Third digit: Other permissions.

    • Example: 700 : Only the owner can read, write, and execute.

  • tar : Extract files from a TAR archive.

  • sudo : Execute a command with superuser privileges (root access).

  • vi : Text editor.

  • code : VSCode editor.

반응형

'웹개발 > 개발자' 카테고리의 다른 글

기초 코드 작성 방법 [rule of thumb]  (3) 2024.09.03
Git Zone & Git Flow  (0) 2024.09.03
Git 구조 및 Remote vs Local  (0) 2024.09.01
Git & GitHub  (2) 2024.08.27