28 May 2026
02 April 2026
How to find files? How to find directories?
How to find files?
du -sk ./* | sort -nr
or
du -sk ./* | grep -i "keyword" | sort -nr
or
$ find . -maxdepth 1 -iname "*keyword*" -type f -printf "%T+ %p\n" | sort -r
or
$ find . -maxdepth 1 -iname "*keyword*" -type f -exec du -sk {} + | sort -nr
How to find directories?
$ du -sk ./*/ | sort -nr
or
$ du -sk ./*/ | grep -i "keyword" | sort -nr
or
$ find . -maxdepth 1 -iname "*keyword*" -type d -not -path '.' -printf "%T+ %p\n" | sort -r
or
$ find . -maxdepth 1 -iname "*keyword*" -type d -not -path '.' -exec du -sk {} + | sort -nr
20 March 2026
How to find the most largest 10 files on Ubuntu?
find, du, sort, and head commands. . with the specific directory path if you want to search a different location: find . -type f -exec du -Sh {} + | sort -rh | head -n 10
find .: Starts the search from the current directory (.) and traverses all subdirectories recursively.-type f: Restricts the search to regular files only, ignoring directories, links, etc..-exec du -Sh {} +: Executes theducommand on the found files.du: Estimates file space usage.-S: Reports the size of individual files, not including the size of subdirectories (important for listing individual files correctly).-h: Displays sizes in a human-readable format (e.g., 10MB, 2G).{}and+: These are used byfindto pass multiple filenames to a singleducommand efficiently.
|: Pipes the output of thefindcommand to thesortcommand.sort -rh: Sorts the output lines.-r: Reverses the sort order, placing the largest files at the top.-h: Compares human-readable numbers correctly (e.g., understands that 2G is larger than 10M).
| head -n 10: Displays only the first 10 lines of the sorted output (the top 10 largest files).
find . -type f -printf "%s %p\n" | sort -nr | head -n 10
%s) followed by the file path (%p), sorts numerically (-n) in reverse order (-r), and shows the top 10 results. ncdu tool, which is available in the Ubuntu package manager. - Install
ncdu:sudo apt install ncdu. - Run in the directory:
ncdu .(or a specific path, e.g.,ncdu /var/log). This provides an interactive interface to navigate directories and see the largest files and folders.
06 February 2026
on ubuntu terminal, how to remove all the spaces from all the file names in a directory?
05 March 2025
How To Search And Replace String Across Multiple Files in Vim
https://irian.to/blogs/how-to-search-and-replace-string-across-multiple-files-in-vim
Perform substitution with macros and repeat it
While recording a macro, perform substitution on one file, and repeat the macros across all args.
Assuming the same folder structure and args, here is how it is done:
qq // start macro in q register
%s/stringToBeReplaced/replacementString/ge // the e flag tells vim to not throw an error if there is no match
:wnext //important. This is similar to `:next`, but it also writes the current file
q // stop macro
999@q //repeat this macros either 999 times or to remaining files.
That's it!
23 June 2023
08 March 2023
How to install .deb files on Ubuntu?
https://linuxconfig.org/install-deb-file-on-ubuntu-22-04-jammy-jellyfish-linux
$ sudo dpkg -i example.deb
If the package requires dependencies that aren’t already on your system, you will see
this error in the terminal:
dpkg: error processing package
Don’t fret, because we can install the required dependencies with a single command,
assuming that they are available in Ubuntu’s package repository. Just run this command
to install the dependencies:
$ sudo apt install -f
13 October 2022
How to find who and when modified each line of a file last time, and how to find who and when added/deleted a portion of a code line of a file since the very beginning
01 January 2022
How to Remove all large files by a file extension name e.g. .mp4 or by file size from Every Commit in git?
How to Remove all large files by a file extension name e.g. .mp4 or by file size from Every Commit in git?
22 August 2021
Can open Excel files locally but not from network
Can open Excel files locally but not from network
Problem:
Can open Excel files locally but not from network
Solution:
File -> Options -> Trust Centre -> Trust Centre Settings -> Protected View.
Clear all the ticks. Click OK.
10 August 2021
How to read a file, which only contains a string, into Python, and then convert the string into a list?
How to read a file, which only contains a string, into Python, and then convert the string into a list?
from pathlib import Path
txt = Path('filename.txt').read_text()
list_ = list(txt.split('; '))
29 July 2021
How to concatenate all the text files in a folder?
How to concatenate all the text files in a folder?
https://stackoverflow.com/questions/13613336/python-concatenate-text-files
ls | xargs cat | tee output.txt
27 July 2021
How to concatenate all the text files in a directory with Python?
How to concatenate all the text files in a directory with Python?
https://stackoverflow.com/questions/13613336/python-concatenate-text-files
import glob2
filenames = glob2.glob('*.txt') # list of all .txt files in the directory
with open('outfile.txt', 'w') as f:
for file in filenames:
with open(file) as infile:
f.write(infile.read()+'\n')
09 July 2021
How to get lost files back resulting from running git add and git restore -s@ -SW?
How to get lost files back resulting from running git add and git restore -s@ -SW?
Problem:
suppose you ran
$ git add .
then you ran
$ git status
and saw that you have added some files which you did not want to add.
(You did not run
$ git commit
)
then you wanted to remove them from the index.
In haste, you ran
$ git restore -s@ -SW
resulting in those files are gone away from your working tree (resulted from -W).
You want to get them back.
Solution:
Run
$ git fsck --cach --no-reflogs --lost-found --unreachable head
You will get a list of SHA1, which point to your lost files.
Then run
$ git show SHA1 > name_of_lost_file
one by one, every lost file will now be in your current work directory!
01 July 2021
How to find all the files containing the string 'abc' in the current directory and all the sub-directories
How to find all the files containing the string 'abc' in the current directory and all the sub-directories?
find . -type f | xargs fgrep '...'
20 June 2021
How to list all html files in a directory recursively sorted by file size?
How to list all html files in a directory recursively sorted by file size?
$du -a -h | sort -nr | grep 'html' | less
Note:
1. '-a' means all files and directories, not just directories.
2. '-h' means human readable.
3. '-n' means numeric sort.
4. '-r' means recursive.
24 March 2021
How to redirect 'print' output to a file using python?
How to redirect 'print' output to a file using python?
import sys
orig_stdout = sys.stdout
f = open('out.txt', 'w')
sys.stdout = f
for i in range(2):
print 'i = ', i
sys.stdout = orig_stdout
f.close()
29 July 2019
How can I find out if a specific program is installed?
scp [source file] [username]@[destination server]:.
scp cool_stuff.txt sanjeev@example.com:.
Remember not to miss the colon and full stop at the end.
https://superuser.com/questions/850740/how-to-upload-local-file-to-server-through-linux-terminal
11 February 2019
23 March 2018
How to associate .docx with Microsoft Word in Windows 10?
Open 'File Explorer'.
Browse to the .docx file you want to open but failed.
Select it by clicking it.
Click 'Home' tab in the menu on the top.
Click the downward triangle beside 'Open'.
Click 'Choose another app'.