Ls: Difference between revisions

From Leechfinger
Jump to navigationJump to search
Created page with "Category:Commands"
 
Qais (talk | contribs)
No edit summary
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
"ls" is the list directory command, below are some of the flags we normally use.
=== Show only directories ===
<syntaxhighlight lang="bash">$ ls -d */‎</syntaxhighlight>
=== Don't show group and owner ===
<syntaxhighlight lang="bash">$ ls -lgo‎</syntaxhighlight>
=== Newest files first ===
<syntaxhighlight lang="bash">$ ls -lt</syntaxhighlight>
=== File size and sort ===
<syntaxhighlight lang="bash">$ ls -sSh</syntaxhighlight>
=== Show modification time ===
<syntaxhighlight lang="bash">$ ls -lgot --time-style=long-iso</syntaxhighlight>
=== Sorting files by extension/version ===
<syntaxhighlight lang="bash">
$ ls -lgo --sort=extension
// or sort by version
$ ls -lgo --sort=version
</syntaxhighlight>
=== Delete files using inode ===
<syntaxhighlight lang="bash">
$ ls -i
175965192 hello
$ find . -maxdepth 1 -type f -inum 175965192
./hello
$ find . -maxdepth 1 -type f -inum 175965192 -delete
$ ls -i
$
</syntaxhighlight>
===Delete directory with inode===
<syntaxhighlight lang="bash">
rm -rf "$(find . -maxdepth 1 -type d -inum 175965181)"
</syntaxhighlight>
[[Category:Commands]]
[[Category:Commands]]

Latest revision as of 21:37, 3 May 2025

"ls" is the list directory command, below are some of the flags we normally use.

Show only directories

$ ls -d */‎

Don't show group and owner

$ ls -lgo‎

Newest files first

$ ls -lt

File size and sort

$ ls -sSh

Show modification time

$ ls -lgot --time-style=long-iso

Sorting files by extension/version

$ ls -lgo --sort=extension 

// or sort by version 
$ ls -lgo --sort=version

Delete files using inode

$ ls -i 
175965192 hello
$ find . -maxdepth 1 -type f -inum 175965192
./hello
$ find . -maxdepth 1 -type f -inum 175965192 -delete
$ ls -i
$

Delete directory with inode

rm -rf "$(find . -maxdepth 1 -type d -inum 175965181)"