14,957
edits
| Line 45: | Line 45: | ||
== file operation == | == file operation == | ||
=== | === Find a file by filename === | ||
* {{Gd}} {{kbd | key=locate}} command ({{Linux}}) ex: {{kbd | key= locate ''filename''}} to locate the filename quickly. <ref>[https://blog.longwin.com.tw/2008/01/linux_quick_find_file_locate_2008/ Linux 快速尋找檔案 - locate - Tsung's Blog]</ref> | * {{Gd}} {{kbd | key=locate}} command ({{Linux}}) ex: {{kbd | key= locate ''filename''}} to locate the filename quickly. <ref>[https://blog.longwin.com.tw/2008/01/linux_quick_find_file_locate_2008/ Linux 快速尋找檔案 - locate - Tsung's Blog]</ref> | ||
| Line 52: | Line 52: | ||
* {{kbd | key=dir}} command ({{Win}}) ex: {{kbd | key= dir /s ''filename''}} <ref>[http://www.computerhope.com/issues/ch000309.htm How to find a file in MS-DOS.]</ref><ref>/S 顯示指定目錄及所有子目錄中的檔案。 (引用自 dir /? 命令說明)</ref> {{exclaim}} I have no idea to specify the file path to find the file. | * {{kbd | key=dir}} command ({{Win}}) ex: {{kbd | key= dir /s ''filename''}} <ref>[http://www.computerhope.com/issues/ch000309.htm How to find a file in MS-DOS.]</ref><ref>/S 顯示指定目錄及所有子目錄中的檔案。 (引用自 dir /? 命令說明)</ref> {{exclaim}} I have no idea to specify the file path to find the file. | ||
=== | === Copy & overwrite file === | ||
overwrite file without prompt (confirmation): [http://www.computerhope.com/unix/ucp.htm cp] command | overwrite file without prompt (confirmation): [http://www.computerhope.com/unix/ucp.htm cp] command | ||
* {{kbd | key=cp -f ''to_be_copy.file'' ''to_be_overwrote.file''}} ({{Linux}})<ref>[http://www.ewdna.com/2012/05/linux-cp-force-overwrite.html Linux:檔案複製強制覆寫, cp force overwrite @ 符碼記憶]</ref> | * {{kbd | key=cp -f ''to_be_copy.file'' ''to_be_overwrote.file''}} ({{Linux}})<ref>[http://www.ewdna.com/2012/05/linux-cp-force-overwrite.html Linux:檔案複製強制覆寫, cp force overwrite @ 符碼記憶]</ref> | ||
* {{kbd | key=/bin/cp -f ''to_be_copy.file'' ''to_be_overwrote.file''}} ({{Linux}}) | * {{kbd | key=/bin/cp -f ''to_be_copy.file'' ''to_be_overwrote.file''}} ({{Linux}}) | ||
=== | === Copy old directory to new directory === | ||
* {{kbd | key=cp -a ''old_dir new_dir/''}} ({{Linux}})<ref> | * {{kbd | key=cp -a ''old_dir new_dir/''}} ({{Linux}})<ref> | ||
<pre>from manual: | <pre>from manual: | ||
| Line 73: | Line 73: | ||
** cp ''old_dir/* new_dir'' | ** cp ''old_dir/* new_dir'' | ||
=== | === Delete files or directory === | ||
delete all files or directory | delete all files or directory | ||
* {{kbd | key=rm -rf ''/Name_of_directory''}} to delete all files under the '''Name_of_directory'' ({{Linux}})<ref><nowiki>[OPTION]</nowiki> | * {{kbd | key=rm -rf ''/Name_of_directory''}} to delete all files under the '''Name_of_directory'' ({{Linux}})<ref><nowiki>[OPTION]</nowiki> | ||
| Line 91: | Line 91: | ||
* {{kbd | key= <nowiki>find . -name 'naming_rule' -type f -delete</nowiki>}} <ref>[http://danilo.ariadoss.com/how-to-recursively-remove-ds_store-files-on-mac-os-x/ How to recursively remove .DS_Store files on Mac OS X | Tangential Musings]</ref> | * {{kbd | key= <nowiki>find . -name 'naming_rule' -type f -delete</nowiki>}} <ref>[http://danilo.ariadoss.com/how-to-recursively-remove-ds_store-files-on-mac-os-x/ How to recursively remove .DS_Store files on Mac OS X | Tangential Musings]</ref> | ||
=== | === Download file from remote server === | ||
* FTP | * FTP | ||
* wget (with progress bar): {{kbd | key= <nowiki>wget http://path.to/file</nowiki>}} | * wget (with progress bar): {{kbd | key= <nowiki>wget http://path.to/file</nowiki>}} | ||
| Line 98: | Line 98: | ||
=== | === File compression and decompression === | ||
compress | compress | ||
* {{kbd | key= <nowiki>pv big.file | gzip > big.file.gz</nowiki> }}({{Linux}})<ref>[http://www.catonmat.net/blog/unix-utilities-pipe-viewer/ A Unix Utility You Should Know About: Pipe Viewer - good coders code, great reuse]</ref> keep the original file | * {{kbd | key= <nowiki>pv big.file | gzip > big.file.gz</nowiki> }}({{Linux}})<ref>[http://www.catonmat.net/blog/unix-utilities-pipe-viewer/ A Unix Utility You Should Know About: Pipe Viewer - good coders code, great reuse]</ref> keep the original file | ||
| Line 111: | Line 111: | ||
* [http://www.cyberciti.biz/faq/tar-extract-linux/ Linux: tar Extract Files] | * [http://www.cyberciti.biz/faq/tar-extract-linux/ Linux: tar Extract Files] | ||
=== | === List directory or files / list directory contents === | ||
* ls ({{Linux}}) ex: {{kbd | key= ls -lh}} List detailed information of files <ref>[http://linux.vbird.org/linux_basic/0210filepermission.php 鳥哥的 Linux 私房菜 -- Linux 的檔案權限與目錄配置]</ref> <ref>[OPTION] | * ls ({{Linux}}) ex: {{kbd | key= ls -lh}} List detailed information of files <ref>[http://linux.vbird.org/linux_basic/0210filepermission.php 鳥哥的 Linux 私房菜 -- Linux 的檔案權限與目錄配置]</ref> <ref>[OPTION] | ||
* -l use a long listing format | * -l use a long listing format | ||
| Line 120: | Line 120: | ||
* List all files and directories including hidden ones in the current directory. On {{Win}} is {{kbd | key=<nowiki>dir /a</nowiki>}}, and on {{Mac}} or {{Linux}} is {{kbd | key=<nowiki>ls -a</nowiki>}}<ref>[http://www.computerhope.com/issues/ch001039.htm How to see hidden files in MS-DOS and the Command Prompt]</ref><ref>[http://www.cyberciti.biz/faq/bash-shell-display-only-hidden-dot-files/ Bash Shell: Display All Hidden Dot Files In a Directory]</ref>. | * List all files and directories including hidden ones in the current directory. On {{Win}} is {{kbd | key=<nowiki>dir /a</nowiki>}}, and on {{Mac}} or {{Linux}} is {{kbd | key=<nowiki>ls -a</nowiki>}}<ref>[http://www.computerhope.com/issues/ch001039.htm How to see hidden files in MS-DOS and the Command Prompt]</ref><ref>[http://www.cyberciti.biz/faq/bash-shell-display-only-hidden-dot-files/ Bash Shell: Display All Hidden Dot Files In a Directory]</ref>. | ||
=== | Verify if a file or a folder exists | ||
* On {{Linux}}: {{kbd | key= ls /path/to/file}} or {{kbd | key= ls -d /path/to/folder/}} e.g. {{kbd | key= ls -d ~/}} to list your home directory<ref>[https://linuxconfig.org/single-linux-command-to-return-to-home-directory Single linux command to return to home directory]</ref>. | |||
* On {{Win}}: | |||
** {{kbd | key= dir C:\path\to\file}} or {{kbd | key= dir C:\path\to\folder\}} | |||
** {{kbd | key= IF EXIST}} e.g. [http://stackoverflow.com/questions/3022176/how-to-verify-if-a-file-exists-in-a-windows-bat-file How to verify if a file exists in a Windows .BAT file? - Stack Overflow] | |||
=== Rename (move) files or directory === | |||
* {{kbd | key=mv ''old_folder_name new_folder_name''}} ({{Linux}})<ref>[http://www.liamdelahunty.com/tips/linux_rename_directory.php Linux Rename Files, Folders or Directories]</ref> | * {{kbd | key=mv ''old_folder_name new_folder_name''}} ({{Linux}})<ref>[http://www.liamdelahunty.com/tips/linux_rename_directory.php Linux Rename Files, Folders or Directories]</ref> | ||
* {{kbd | key=mv ''/path/to/file /path/to/new_folder_name''}} ({{Linux}}) | * {{kbd | key=mv ''/path/to/file /path/to/new_folder_name''}} ({{Linux}}) | ||
| Line 126: | Line 132: | ||
=== | === Print the current directory / where am i === | ||
* {{Linux}}: {{kbd | key= pwd}} (print working directory) | * {{Linux}}: {{kbd | key= pwd}} (print working directory) | ||
* {{Win}}: {{kbd | key= echo %cd%}} (current directory) <ref>[http://stackoverflow.com/questions/921741/windows-equivilent-to-unix-pwd Windows equivilent to UNIX pwd - Stack Overflow]</ref> | * {{Win}}: {{kbd | key= echo %cd%}} (current directory) <ref>[http://stackoverflow.com/questions/921741/windows-equivilent-to-unix-pwd Windows equivilent to UNIX pwd - Stack Overflow]</ref> | ||
=== | === Change directory to my home directory === | ||
* {{kbd | key= cd ~/}} or {{kbd | key= cd $HOME}} ({{Linux}}) will switch to my home directory ex: /Users/ACCOUNT<ref>[http://superuser.com/questions/271925/where-is-the-home-environment-variable-set linux - Where is the $HOME environment variable set? - Super User]</ref> | * {{kbd | key= cd ~/}} or {{kbd | key= cd $HOME}} ({{Linux}}) will switch to my home directory ex: /Users/ACCOUNT<ref>[http://superuser.com/questions/271925/where-is-the-home-environment-variable-set linux - Where is the $HOME environment variable set? - Super User]</ref> | ||
* {{kbd | key= cd %UserProfile%}} ({{Win}}) will switch to my home directory ex: C:\Users\ACCOUNT more on [[MS_Windows_Explorer]]<ref>[http://weka.wikispaces.com/Where+is+my+home+directory+located%3F weka - Where is my home directory located?]</ref> | * {{kbd | key= cd %UserProfile%}} ({{Win}}) will switch to my home directory ex: C:\Users\ACCOUNT more on [[MS_Windows_Explorer]]<ref>[http://weka.wikispaces.com/Where+is+my+home+directory+located%3F weka - Where is my home directory located?]</ref> | ||