CLI (Command-Line Interface) 2

Garam·2023년 8월 1일
0

The Odin Project

목록 보기
2/14

https://swcarpentry.github.io/shell-novice/03-create.html



Creating Directories


$ mkdir folderName

Make directory in the current working directory.

$ mkdir -p ../project/data ../project/result

-p = allows mkdir to create a directory with a nested subdirectories in a single operation

$ ls -FR ../project

-R = list all nested subdirectories within a directory

$ cd folderName

$ nano draft.txt

nano = a text editor that only work with plain character data (no tables or images)

$ touch my_file.txt

generates new empty file (to be used in other programs which require empty files have already been generated)




Moving Files and Directories


$ mv thesis/draft.txt thesis/quotes.txt

mv = ‘moving’, draft.txt를 quote.txt에 덮어씌우고 원 파일은 삭제됨
(경고없이 바로 삭제되므로 주의 요)
mv -i (or mv -interactive)는 덮어씌우기 전 한번 물어봐줌.

$ mv thesis/quotes.text .

quotes.txt를 . 로 옮김 (=current working directory!!)




Copying Files and Directories


$ cp quotes.txt quotations.txt

quotes 파일을 quotations라는 새로운 파일로 복사.
결과적으로 같은 파일이 두 개 생김.

$ mkdir quote_backup
$ cp quotes.txt quotations.txt quote_backup/

두 파일을 quote_backup 폴더로 복사

$ cp 1.txt 2.txt 3.txt

→ error cp: target 3.txt is not a directory

$ cp -r thesis thesis_backup

To copy a directory, add the recursive option -r option.



Wildcards for Accessing Multiple Files at Once


*

*.pdb represents ethane.pdb propane.pdb ... every file ends with '.pdb'
p*.pdb represents pentane.pdb propane.pdb ...


?

It represents exactly one character.
?ethane.pad could represent methane.pdb
whereas *ethane.pdb represents both ethan.pdb, methane.pdb

  • Combination

???ane.pdb = cubane.pdb ethane.pdb octane.pdb



Removing files and directories


$ rm quote.txt

Removes the file.
❗️ DELETING IS FOREVER: The Unix shell doesn’t have a trash bin. No recovery.
Tools for finding and recovering deleted files do exit, but there’s no guarantee they’ll work in any particular situation.

$ rm -i

-i prompts warning for safe removal.

$ rm -r thesis

By adding -r, we can remove a directory and all its contents.
To be safe, use rm -r -i.




0개의 댓글