Visit Our UNIX and Linux User Community


List only hidden files, not use . option


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List only hidden files, not use . option
# 1  
Old 06-05-2013
List only hidden files, not use . option

Hi

I have a prompt like this:
Code:
PS1='\[\e[1;33m\]\u@\h \[\e[1;34m\]\w $(es=$?; [[ $es -ne 0 ]] && echo "\[\e[1;31m\]" || echo "\[\e[1;32m\]")[$(ls | wc -l):$(($(ls -ad .* | wc -l)-2))]\$\[\e[0m\]'

It works like it should, but have a bug.

Problem is the counting of hidden files
Code:
$(($(ls -ad .* | wc -l)-2))

Code:
echo $(($(ls -ad .* | wc -l)-2))

The . seems to create the problem when I cut and past to the screen.
It works correct, but gives extra/wrong character displayed on my screen.

Simple test
echo $PS1 in my home folder gives:
Code:
\[\e[1;33m\]\u@\h \[\e[1;34m\]\w $(es=$?; [[ $es -ne 0 ]] && echo "\[\e[1;31m\]" || echo "\[\e[1;32m\]")[$(ls | wc -l):$(($(ls -ad . .. .aptitude .bash_history .bashrc .cache .nano_history .ncftp .profile .selected_editor .ssh .subversion | wc -l)-2))]\$\[\e[0m\]

The extra is in red

Is there another way to get correct hidden files, that does not create this mess?
# 2  
Old 06-11-2013
I use "ls -A" to see hidden files not . or .. as well as visible files. If you want to see only hidden, You can say "ls .??*z" as long as there are no short names, or "ls -A | grep '^\.' ". With "A", no need to subtract 2. You can "grep -c '^\.' " to get count.
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 06-11-2013
Thanks allot.
Getting rid of the ls -ad .*, did fix it.
Code:
PS1='\[\e[1;33m\]\u@\h \[\e[1;34m\]\w $(es=$?; [[ $es -ne 0 ]] && echo "\[\e[1;31m\]" || echo "\[\e[1;32m\]")[$(ls | wc -l):$(ls -A|grep "^\."|wc -l)]\$\[\e[0m\]'

# 4  
Old 06-12-2013
grep ...|wc -l
=
grep -c ...
This User Gave Thanks to DGPickett For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #217
Difficulty: Medium
Network operating systems can be embedded in a router or hardware firewall that operates the functions in the physical layer (layer 1).
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsync - how to copy hidden folder or hidden files when using full path

Hello. I use this command : rsync -av --include=".*" --dry-run "$A_FULL_PATH_S" "$A_FULL_PATH_D"The data comes from the output of a find command. And no full source directories are in use, only some files. Source example... (2 Replies)
Discussion started by: jcdole
2 Replies

2. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

3. AIX

Moving Hidden files to normal files

I have a bunch of hidden files in a directory in AIX. I would like to move these hidden files as regular files to another directory. Say i have the following files in directory /x .test~1234~567 .report~5678~123 .find~9876~576 i would like to move them to directory /y as test~1234~567... (10 Replies)
Discussion started by: umesh.narain
10 Replies

4. UNIX for Dummies Questions & Answers

List all directories hidden or not hidden

I want to list all directories hidden or not hidden. ls -ld */ => shows only not hidden directories so i guess the answer would be to add the a option to show all files ls -lad */ => not working :confused: ls -la | grep "^d" => works But I would like to know why I can't use ls -lad... (4 Replies)
Discussion started by: servus
4 Replies

5. UNIX for Dummies Questions & Answers

Hidden files

How to list out only the hidden files from a directory ? Thanks (4 Replies)
Discussion started by: pandeesh
4 Replies

6. UNIX for Dummies Questions & Answers

hidden files

I usually use ls -al | awk '{sum = sum + $5} END {print sum}' to sum the size of all files in a directory. However this command includes the hidden files. Is there a command to just add up all the files/sub-directories excluding the hidden files (begins with . and ..) I wanted to check the... (10 Replies)
Discussion started by: lhareigh890
10 Replies

7. Programming

Listing hidden files

I'm writing a c program to list the files in a given directory but I also want to display the hidden files. I can't figure this out in c. Does anyone know how to do this? Here's the code I have so far: #include <unistd.h> #include <stdio.h> #include <dirent.h> #include <string.h> #include... (2 Replies)
Discussion started by: snag49ers
2 Replies

8. UNIX for Dummies Questions & Answers

Hidden Files in Linux

Hi, I want to know how to create a hidden file in linux?? Regards Arun.Kakarla (3 Replies)
Discussion started by: Arun.Kakarla
3 Replies

9. Shell Programming and Scripting

Finding Hidden files and protecting the folder containing hidden files from deletion

Hi. I have a script which is deleting files with a particular extension and older than 45 days.The code is: find <path> -name "<filename_pattern>" -mtime +45 -exec rm {} \; But the problem is that some important files are also getting deleted.To prevent this I have decide to make a dummy... (4 Replies)
Discussion started by: pochaw
4 Replies

Featured Tech Videos