How do I assign ls to an array in Linux Bash?
It would be this array=($(ls -d */)) EDIT: See Gordon Davisson’s solution for a more general answer (i.e. if your filenames contain special characters). This answer is merely a syntax correction.
It would be this array=($(ls -d */)) EDIT: See Gordon Davisson’s solution for a more general answer (i.e. if your filenames contain special characters). This answer is merely a syntax correction.
Use find: find . find /home/dreftymac If you want files only (omit directories, devices, etc): find . -type f find /home/dreftymac -type f
Use find: find . -name \*.txt -print On systems that use GNU find, like most GNU/Linux distributions, you can leave out the -print.
Unfortunately your quest won’t be possible in general, as there are only 3 distinct time values stored for each of your files as defined by the POSIX standard (see Base Definitions section 4.8 File Times Update) Each file has three distinct associated timestamps: the time of last data access, the time of last data modification, … Read more
If you give find an absolute path to start with, it will print absolute paths. For instance, to find all .htaccess files in the current directory: find “$(pwd)” -name .htaccess or if your shell expands $PWD to the current directory: find “$PWD” -name .htaccess find simply prepends the path it was given to a relative … Read more
Use egrep-style extended pattern matching. ls !(*.jar) This is available starting with bash-2.02-alpha1. Must first be enabled with shopt -s extglob As of bash-4.1-alpha there is a config option to enable this by default.
This is exactly why you should not use UPPER_CASE_VARS. $PATH is a variable used by the shell to find executables on your system. As soon as you over-write it with user input, your script can no longer find anything that does not reside in whatever the input was. In this case, you entered /bin, so … Read more
*/ is a pattern that matches all of the subdirectories in the current directory (* would match all files and subdirectories; the / restricts it to directories). Similarly, to list all subdirectories under /home/alice/Documents, use ls -d /home/alice/Documents/*/
Those are not really files on disk (as you mention) but they are also not files in memory – the names in /proc correspond to calls into the running kernel in the operating system, and the contents are generated on the fly. The system doesn’t know how large the files would be without generating them, … Read more