Friday, August 19, 2022
HomeNetworkingThe best way to discover recordsdata on Linux and make it simple...

The best way to discover recordsdata on Linux and make it simple to seek out them once more


The cd command makes it simple to change to a different listing on Liniux, however provided that you realize the place you’re heading. On this submit, I focus on a few tips for shifting between recognized areas and supply a script for locating and “remembering” recordsdata or areas that you simply may need to reuse.

One of many best issues to do with the cd command is return to your own home listing no matter the place you might be sitting within the file system in the meanwhile. Simply sort cd by itself, and also you’ll be again in your house listing. Typing cd ~ will do the identical factor, although including the tilde received’t get you there any quicker.

The cd .. command will again you up one listing whereas cd . does nothing in any respect. The logic of the latter is, in any case, “transfer me into the listing that I’m already sitting in”. The cd – command, however, will take you again to no matter listing you have been positioned in beforehand. It additionally confirms your transfer earlier than sending the following command line immediate.

$ cd /tmp   # transfer to /tmp
$ cd ~ # transfer to dwelling listing $ cd – # transfer again to earlier listing
/tmp $

Utilizing the discover command

The discover command is used to find directories or recordsdata. To discover a listing or file, use a command like certainly one of these:

$ discover /usr -type d -name bin -ls          # discover a listing
$ discover /usr -type f -name zcat -print      # discover a file

The -type specs aren’t wanted except you need to make certain that you’ll see solely recordsdata or directories. The distinction between -ls and –print is that -ls exhibits each the names of the positioned recordsdata or directories and their particulars (permissions, sizes, and many others.) whereas the -print exhibits solely the names.

If you happen to’re looking for recordsdata or directories exterior of your own home listing, including 2>/dev/null to the top of the command will imply that you simply received’t run into “Permission denied” errors for these recordsdata or directories you don’t have learn entry to.

$ discover /usr -type d -name bin -ls 2>/dev/null
$ discover /usr -type f -name zcat -print 2>/dev/null

Saving areas with symbolic hyperlinks

For recordsdata or directories that you simply anticipate to make use of usually, creating symbolic hyperlinks that time to them can prevent from having to recollect their areas or discover them time and again.

Making a symbolic hyperlink is straightforward. Discover the file after which use the ln -s command to create the symbolic hyperlink as on this instance:

$ discover / -type f -name little_endian.h 2>/dev/null
/usr/embody/linux/byteorder/little_endian.h
$ ln -s /usr/embody/linux/byteorder/little_endian.h .

The ln -s command above would create the symbolic hyperlink in your present location. You’ll most likely need this to be your own home listing.

Saving areas with a script

The script beneath will discover a file or listing for you and, if you would like, create a symbolic hyperlink that factors to it. Actually, if it finds a number of recordsdata or directories that match your specification, it can provide to create a symbolic hyperlink to every of them and can add a digit to the top of every hyperlink after the primary to distinguish them. If you happen to reply “n” to the immediate asking whether or not to create a symlink, it is not going to create any symbolic hyperlinks, however will nonetheless present you the recordsdata or directories that it discovered.

#!/bin/bash

echo -n "What are you in search of?> "
learn title

echo -n "File or listing? [f/d]> "
learn sort

echo -n "Place to begin?> "
learn begin

locs=`discover $begin -type $sort -name $title -ls 2>/dev/null | awk '{print $NF}'`

num=""

for loc in $locs
do
    echo $loc
    echo -n "Create a symlink? [y/n]> "
    learn ans
    if [ $ans == "y" ]; then
        if [ -f $name$num ]; then		# take away
            rm $title$num			# previous
        fi					# hyperlinks
        echo "ln -s $loc $title$num"
        ln -s $loc $title$num
        ((num++))
    fi
finished

Word: The script as proven will delete current recordsdata or hyperlinks with the identical names as these it might create. Delete the traces with the feedback if you do not need this to occur. If you happen to do, you’ll be able to rename the conflicting recordsdata after which run the script once more.

Wrap-Up

Transferring round within the Linux file system is straightforward, however with just a few instructions, you can also make it simpler to seek out and keep in mind recordsdata and directories that you’re more likely to want usually.

Be a part of the Community World communities on Fb and LinkedIn to touch upon matters which might be high of thoughts.

Copyright © 2022 IDG Communications, Inc.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments