Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What options exist for the .hidden file? I wanted to hide certain filetypes in a folder, but simply putting *.out, which I assumed would hide all files ending in .out, didn't work. :(

I'm using Nautilus.

UPDATE: I guess if this option doesn't exist, a bash shell could be created that, when executed in a directory, finds all files with matching endings and writes them to the .hidden file. I don't have any experience with the command-line but I'll try this :).

share|improve this question
    
Shorter: ls -- *.out > .hidden –  don_crissti Jun 5 '13 at 20:31
add comment

3 Answers

up vote 0 down vote accepted

New answer: It seems you meant something other than I thought you did. You create a literal .hidden file listing all the files you want the Nautilus file manager to hide by default you can use this command (from @Jóhann 's answer):

for i in *.out; do echo "$i"; done > .hidden

Replacing .out with the file extension you wish to hide.

Old answer:

If all the files in question share the same extension, and no other files do, then a simple shell command will do the trick. For example, for *.out files:

for i in ./*.out; do mv "$i" ./."${i#./}"; done

This command will move all files in the current directory matching *.out to .<name>.out

share|improve this answer
1  
basename is almost never necessary because simple parameter expansion can do its job. Also, for maximum safety, prefix globs with ./. for i in ./*.out; do mv "$i" ./"${i#./}"; done –  jw013 Feb 14 '12 at 21:40
    
@jw013 I get a syntax error with your version. –  Amazed Feb 14 '12 at 21:45
    
Fixed: for i in ./*.out; do mv "$i" ./."${i#./}"; done I forgot the . in the destination so it would have tried to rename a file to itself. There should be no syntax error, just a logic error in the original. –  jw013 Feb 14 '12 at 21:49
    
That fixed it; added to answer. –  Amazed Feb 14 '12 at 21:51
    
Oooo, this is cool. But can this be modified to add filenames matching a chosen file ending to a .hidden file. The scenario where that would be beneficial is in a directory containing only a .tex and its associated files that I don't need to see. I assume the compiler couldn't find the files with the dot in front, so a more practical solution seems to be to keep the filenames (which will be constant) in a .hidden file –  Jóhann Feb 14 '12 at 22:14
show 1 more comment

Based on the answer from Amazed, I created a shell command to do what I needed it to do.

for i in *.out; do echo "$i"; done > .hidden

This seems to work, is it possible to apply a shell command to all subdirectories of a chosen directory (actually, that's probably another question)

share|improve this answer
add comment

Just for fun, I'll improve Jóhann's answer a bit. Instead of overwriting the whole file, this command checks whether a file name is already in the .hidden file, and appends it if not.

for i in *.out; do grep -qxF "$i" tout || echo $i; done

If you want a more general script, this should work:

#!/bin/bash -e

if [ $# -gt 3 ]; then
        echo "Usage: $0 [directory [extension [listfile]]]"
        echo 'Defaults to "." ".out" ".hidden"'
        exit 1
fi

# Apply defaults.
dir=${1:-.}
ext=${2:-.out}
listf=${3:-.hidden}

# Construct the list file.
list="$dir/$listf"

# Make sure the list file exists or the first `grep` will print an error.
[ -f "$list" ] || touch "$list"

# Glob all the files
for filename in "$dir"/*"$ext"; do
        # Check whether the list contains the file name
        if ! grep -qxF "$filename" "$list"; then
                # If not, add it.
                echo "$filename" >>"$list"
        fi
done
share|improve this answer
    
Nice, I'll have to dig through this and try and understand the code. This could easily be modified to take a list of extensions, yes? –  Jóhann Feb 15 '12 at 9:36
    
@Jóhann Yes, it shouldn't be too hard to modify it. It'll be a good exercise for you, but if you have trouble getting it right, comment again and I'll help. –  Kevin Feb 15 '12 at 15:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.