Operations 6 min read

Boost Your Linux Productivity with 3 Powerful File‑Handling Tricks

Learn how to quickly locate, filter, and rename files on Linux using concise ls, find, du, and rename commands, plus practical examples that cut down search time, reveal the largest items, count directory contents, and automate batch renaming.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Boost Your Linux Productivity with 3 Powerful File‑Handling Tricks

Finding Files Efficiently

When you need to locate files, find is the obvious choice, but for large search scopes it can be slow. Using ls -ltr lists files by modification time, showing the most recent files at the bottom:

$ ls -ltr ~/bin | tail -3
-rwx------ 1 shs shs   229 Sep 22 19:37 checkCPU
-rwx------ 1 shs shs   285 Sep 22 19:37 ff
-rwxrw-r-- 1 shs shs  1629 Sep 22 19:37 test2

To list only today’s updates you can combine ls with a time‑style filter and grep:

$ ls -al --time-style=+%D | grep `date +%D`

Filtering Find Output

If the target file may reside outside the current directory, find offers flexibility. The following command skips hidden directories, selects regular files, and shows only those modified within the last day:

$ find . -not -path '*/.*' -type f -mtime -1 -ls

The -not option inverts the -path test, preventing matches in dot‑prefixed directories.

Identifying Largest Files and Directories

Use du to list sizes, pipe through sort -n, and keep the top entries with tail:

$ du -kx | egrep -v "\./.+/" | sort -n | tail -5
918984    ./reports
1053980   ./notes
1217932   ./.cache
31470204  ./photos
39771212  .

The -k flag reports sizes in kilobytes, while -x stops du from crossing into other mounted filesystems.

Counting Files in a Directory

To count all regular files under a specific home directory, combine find with wc -l. Redirecting errors to /dev/null avoids noisy output from unreadable paths:

$ find /home/alvin -type f 2>/dev/null | wc -l
35624

You can limit the search depth with -maxdepth 1 when only the top‑level directory matters:

$ find /home/alvin -maxdepth 1 -type f | wc -l
387

Batch Renaming Files

The mv command renames a single file, but for bulk operations the rename utility is far more efficient. Replace spaces with underscores in all filenames: $ rename 's/ /_/g' * Remove the .txt extension from every file in the current directory: $ rename 's/.txt//g' * In the substitution pattern, the trailing g flag makes the change global, affecting every occurrence in each filename.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxShellBashfile-managementcommand-line
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.