Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
LemonWiki共筆
Search
Search
Appearance
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Linux commands
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== List directory or files / list directory contents === * ls ({{Linux}}) [http://linuxcommand.org/man_pages/ls1.html ls - list directory contents] ** List detailed information of files. e.g. {{kbd | key= ls -lh}}<ref>[http://linux.vbird.org/linux_basic/0210filepermission.php 鳥哥的 Linux 私房菜 -- Linux 的檔案權限與目錄配置]</ref> <ref>[OPTION] * -l use a long listing format * -h, --human-readable; with -l, print sizes in human readable format (e.g., 1K 234M 2G) Quoted from linux {{kbd | key=man ls}}</ref> ** List detailed information of files and sort by modification time. {{kbd | key= ls -lht}} ** List top N files and sort by modification time. {{kbd | key= <nowiki>ls -lht | head -N</nowiki>}} e.g. {{kbd | key= <nowiki>ls -lht | head -10</nowiki>}} First line is the total file size of specified folder.<ref>[http://www.unix.com/unix-for-dummies-questions-and-answers/44493-how-list-top-10-files.html How to list top 10 files | Unix Linux Forums | UNIX for Dummies Questions & Answers]</ref> * ll ({{Linux}}) {{kbd | key= ll}} = {{kbd | key= ls -l}} * Print the entire path of files and '''level-unlimited''' sub-directories in the current directory. On {{Win}} using {{kbd | key= dir/s/b}}, and on {{Linux}} using {{kbd | key= find /path/to/files/ -print}} <ref>[http://superuser.com/questions/159975/making-ls-output-like-dir-b-s linux - Making ls output like dir /b /s - Super User]</ref>. * {{Gd}} create ls command in {{Win}} command prompt: {{kbd | key = echo dir %1 > %systemroot%\system32\ls.bat}} Thanks, hmjd!<ref>[http://stackoverflow.com/questions/9362692/how-to-create-ls-in-windows-command-prompt How to create ls in windows command prompt? - Stack Overflow]</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>. List only filenames and one file per line * {{Win}} {{kbd | key=dir/b}}<ref>[https://smallbusiness.chron.com/copy-list-files-windows-folder-excel-list-40032.html How to Copy a List of Files in a Windows Folder Into an Excel List]</ref> * {{Mac}} {{kbd | key=ls -1}}<ref>[https://www.baeldung.com/linux/list-one-filename-per-line List One Filename Per Line in Linux | Baeldung on Linux]</ref> Verify if a file or a directory exists * On {{Linux}}: {{kbd | key= ls /path/to/file}} or {{kbd | key= ls -d /path/to/directory/}} 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\directory\}} ** {{kbd | key= IF EXIST}} <ref>[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]</ref><ref>[http://stackoverflow.com/questions/2903416/windows-shell-string-operations-changing-backslash-to-slash Windows shell string operations (changing backslash to slash) - Stack Overflow]</ref> <pre> SET a=C:\path\to\file REM -- If the directory was separated the \ symbol & the path NOT contains space IF EXIST %a% (ECHO YES) ELSE (ECHO No) SET a="C:\path\to\directory contains space\space" REM -- If the directory was separated the \ symbol & the path contains space IF EXIST %a% (ECHO YES) ELSE (ECHO No) SET a=C:/path/to/file REM -- If the directory was separated the / symbol, the next command replace / with \ symbol. SET a=%a:/=\% IF EXIST %a% (ECHO YES) ELSE (ECHO No) </pre> troubleshooting <pre> SET a = C:\path\to\file REM -- Correct command: SET a=C:\path\to\file IF EXIST %a% (ECHO YES) ELSE (ECHO No) REM -- the returned result will not correct! </pre>
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki共筆:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)