List all folder and subfolder inside it where folder names start with a* or b* or c* with path - linux

I need a folder and subfolder inside it to be displayed where names that start with A* or B* or C* and display along with path
Below Command Does not Display as expected
$ ls -l | egrep d

You can display the current directory by using the system environment variable PWD. You can combine the PWD with your ls command
using ls -ld
ls -ld $PWD/A* $PWD/B* $PWD/C*
EDIT
If you want a list of all the directories and sub directories you can use the find command.
find . > subfolders.txt && cat subfolders.txt | egrep -i "^./E|^./g"
This command will recursively list all contents on your current working directory and send the output to a txt file named subfolders.txt. Then it will read the contents of subfolders.txt and using egrep, you can filter out anything that starts with "./E" or "./g". the -i option means it is case insensitive.
NOTE: This will also display the files contained in those subfolders.

find . | grep -E '/A|/B|/C'
find is better than ls for your requirements.

Related

How to show ls path of the ls-piped-into-grep output?

Does anyone know how to show the containing directory of an ls output command?
For example in the / I issue ls -R | grep something the output finds the file that matches the something without telling me where the file is located, or it's full path.
According to "ls" command,you can only search for files in the current directory, For global search,please use the "find" command.

shell script to read directory names and create .txt files with the same names in another directory

I have two directories, one called clients and another called test, inside the directory called clients I have some folders, I need a shell script that reads the name of the folders inside clients and creates .txt files with the same name inside the folder test, I am very new to shell and I have no idea how to do this, could you guys help me please?
Try using xargs with ls. ls -F displays all files in the directory client, but then displays the folders with an extra / at the end. the grep uses the extra / in the output of ls -F to only pass folders to the next command. Then, sed 's/\///g removes the extra / from grep, and passes the names to xargs. xargs will then pass the folders to the % symbol, and then make text files with the names.
ls -F client | grep / | sed 's/\///g' | xargs -I % touch tests/%.txt

How to show the amount of files in the sub-folders?

I have a folder named "A", and there are 3 sub-folders in it which are named "A1", "A2", "A3" respectively.
Is there a command to show the amount of files in each sub-folders?
E.g.
A1 5
A2 7
A3 18
Thanks.
Well, you can loop over each subdirectory in ./A and output the number of files/folders contained in each subdirectory with:
for i in A/*; do [ -d "$i" ] && echo "${i##*/} $(ls -1 "$i" | wc -l)"; done
Which just loops over all files and folders in A, and if the current name is a directory, it echos the directory name and a count of the number of files/folders in that directory.
(note: that is a ls -"one" and a wc -"ell")
To include hidden files in the subdirectories use ls -a1 which is -"a"one" and then subtract 2 from each total (for . and ..)
Give that a try and let me know if you have further questions.
Try this
ls -R /path/to/A-diretory
du -ah /path/to/A-direcory //here it will tell the size of files too
if you want to see your listing in tree like structure, use tree command, its a very powerful command having a lot of options.
before that
apt-get install tree (for ubuntu)
tree /path/to/A-directory
You can always refer man command to explore more of a command

how to skip the files in the specific patteren in a folder

I have one folder in this folder contain different kind of files like
qt_fact_info.d20140228
qt_fact_info_is.d20140228
qt_fact_info_bkk.d20140228
qt_fact_info_lb.d20140228
qt_fact_info_sg.d20140228
I want only qt_fact_info.d20140228 this type of files only. I don't want files matching these patterns: *_is,*_bkk,*_lb,*_sg
Please help me how to print the above required kind of files(qt_fact_info.d20140228) by using UNIX shell scripting
You can do it like this:
ls | grep -v '_is\|_bkk\|_lb\|_sg'
grep -v prints everything that does not match the pattern.
\| means or
ls | sends the output of ls to grep for filtering.

How to append list of home directory to a text file and how to move files?

I know a very basic of unix and I am writing a java program which I only need couple of commands to solve my problem.
I appreciate if anyone knows how I can get desired output:
What command I can use to append a full list of objects of my home directory to a file "report.txt". Assume I am in different directory?
What command I can use to move all files in my directory that begin with either a, b, or c, to a subdirectory, sorting, of my current directory?
If I go to /proc directory. What does this command do?
cd 'ps | grep ps| cut -f 1'
I really appreciate if any one can help me out with these.
What command I can use to append a full list of objects of my home directory to a file "report.txt". Assume I am in different directory?
ls -la ~ > report.txt
What command I can use to move all files in my directory that begin with either a, b, or c, to a subdirectory, sorting, of my current directory?
mv a* b* c* yourdirectory
If I go to /proc directory. What does this command do?
cd 'ps | grep ps| cut -f 1'
This command will give "bash: cd: ps | grep ps| cut -f 1: No such file or directory" error

Resources