Last active
February 18, 2023 11:34
-
-
Save yogendra689/c012925b20baf0726b87fca919ec9146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls -lhS # sort in reverse order | |
ls -lhSr # sort in ascending order | |
ls -lhS | head -11 # get 10 big files | |
ls -lahS # include hidden files | |
ls -lRS # recursively sort files including subdirectories | |
du -ah | sort -hr #recursively sort files throughout system | |
ls -l new.txt fff 2>> combined.txt >> combined.txt # combined.txt will add stderr and then stdout | |
Ref: https://linuxhandbook.com/sort-files-by-size/ | |
There are three data streams. One input, stdin (0) and two output data streams stdout (1) and stderr (2). | |
Keyboard is the default stdin device and the screen is the default output device. | |
Output redirection is used with > or >> (for append mode). | |
Input redirection is used with <. | |
yogendra@dd clout % ls -l new.txt fff 2>&1 > combined.txt | |
ls: fff: No such file or directory | |
yogendra@dd clout % cat combined.txt | |
-rw-r--r-- 1 yogendra staff 0 Feb 18 15:51 new.txt | |
yogendra@dd clout % ls -l new.txt fff 2>&1 |> combined.txt | |
yogendra@dd clout % cat combined.txt | |
ls: fff: No such file or directory | |
-rw-r--r-- 1 yogendra staff 0 Feb 18 15:51 new.txt | |
yogendra@dd clout % | |
The stderr can be redirected using 2> or 2>>. | |
The stderr and stdout can be combined using 2>&1. | |
# find file insensitive search | |
alias find_file="find / -iname $1 2> /dev/null" | |
# Script to split a string based on the delimiter | |
my_string="Ubuntu;Linux Mint;Debian;Arch;Fedora" | |
IFS=';' read -ra my_array <<< "$my_string" | |
#Print the split string | |
for i in "${my_array[@]}" | |
do | |
echo $i | |
done | |
# list size of directory with of depth2 | |
du -h -d2 . | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment