ls

awk in bash with ls and variable

无人久伴 提交于 2019-11-29 18:10:48
I wanted to print only the name of files of a specific directory: In this way it works: ls -g --sort=size -r /bin | awk '{print $8,$9,$10,$11,$12,$13}' but if I read the path variable it doesn't work: read PATH ls -g --sort=size -r $(PATH) | awk '{print $8,$9,$10,$11,$12,$13}' Command 'awk' is available in '/usr/bin/awk' It should be: ls -g --sort=size -r ${PATH} | awk '{print $8,$9,$10,$11,$12,$13}' Notice the curly braces. With $(..) , it'll execute the command/function named PATH and substitute the result, which is not what you want. Note that PATH is the poor choice for a variable name as

List all files that do not match pattern using ls [duplicate]

不羁的心 提交于 2019-11-29 13:16:40
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How can I use inverse or negative wildcards when pattern matching in a unix/linux shell? I've read the man page for ls , and I can't find the option to list all that do not match the file selector. Do you know how to perform this operation? For example: lets say my directory is this: > ls a.txt b.mkv c.txt d.mp3 e.flv Now I would like to do something that does the following > ls -[SOME_OPTION] *.txt b.mkv d.mp3

How do I capture the output from the ls or find command to store all file names in an array?

血红的双手。 提交于 2019-11-29 10:41:30
问题 Need to process files in current directory one at a time. I am looking for a way to take the output of ls or find and store the resulting value as elements of an array. This way I can manipulate the array elements as needed. 回答1: To answer your exact question, use the following: arr=( $(find /path/to/toplevel/dir -type f) ) Example $ find . -type f ./test1.txt ./test2.txt ./test3.txt $ arr=( $(find . -type f) ) $ echo ${#arr[@]} 3 $ echo ${arr[@]} ./test1.txt ./test2.txt ./test3.txt $ echo $

pass output as an argument for cp in bash [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-11-28 20:54:07
问题 This question already has answers here : How to pass command output as multiple arguments to another command (4 answers) Closed 3 years ago . I'm taking a unix/linux class and we have yet to learn variables or functions. We just learned some basic utilities like the flag and pipeline, output and append to file. On the lab assignment he wants us to find the largest files and copy them to a directory. I can get the 5 largest files but I don't know how to pass them into cp in one command ls -SF

Finding executable files using ls and grep

谁说胖子不能爱 提交于 2019-11-28 18:58:13
问题 I have to write a script that finds all executable files in a directory. So I tried several ways to implement it and they actually work. But I wonder if there is a nicer way to do so. So this was my first approach: ls -Fla | grep \*$ This works fine, because the -F flag does the work for me and adds to each executable file an asterisk, but let's say I don't like the asterisk sign. So this was the second approach: ls -la | grep -E ^-.{2}x This too works fine, I want a dash as first character,

Unix pipe into ls

好久不见. 提交于 2019-11-28 17:28:33
I thought I understood *nix pipes until now... I have an executable called studio which symlinks to my install of Android Studio and I had assumed I could get the linked-to location with which studio | ls -l But that doesn't work. What it gives me is equivalent to having just run ls -l in the current directory. If I run which studio , I get /home/me/bin/studio . And if I run ls -l /home/me/bin/studio I get the expected output showing me the symlink location. So why doesn't the piped version work? What haven't I grokked about pipes? fedorqui To do that you need xargs : which studio | xargs ls

Cygwin ls command not found [closed]

懵懂的女人 提交于 2019-11-28 16:23:41
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . This is a question that I self-answered on my tech blog where I keep the tech-tips which I need to give to myself from time to time, so I decided to move it over here instead. The original blog post is here: http://thehacklist.blogspot.com/2009/04/cygwin-ls-command-not-found.html If you are a linux enthusiast

Unix's 'ls' sort by name

我是研究僧i 提交于 2019-11-28 15:29:47
Can you sort an ls listing by name? My ls sorts by name by default. What are you seeing? man ls states: List information about the FILEs (the current directory by default). Sort entries alpha‐betically if none of -cftuvSUX nor --sort is specified. : For something simple, you can combine ls with sort . For just a list of file names: ls -1 | sort To sort them in reverse order: ls -1 | sort -r ls from coreutils performs a locale-aware sort by default, and thus may produce surprising results in some cases (for instance, %foo will sort between bar and quux in LANG=en_US ). If you want an

Linux delete file with size 0 [duplicate]

放肆的年华 提交于 2019-11-28 15:11:55
This question already has an answer here: How to delete many 0 byte files in linux? 10 answers How do I delete a certain file in linux if its size is 0. I want to execute this in an crontab without any extra script. l filename.file | grep 5th-tab | not eq 0 | rm Something like this? This will delete all the files in a directory (and below) that are size zero. find /tmp -size 0 -print0 |xargs -0 rm -- If you just want a particular file; if [ ! -s /tmp/foo ] ; then rm /tmp/foo fi James.Xu you would want to use find : find . -size 0 -delete To search and delete empty files in the current

How do I list one filename per output line in Linux?

自闭症网瘾萝莉.ら 提交于 2019-11-28 13:45:56
问题 I'm using ls -a command to get the file names in a directory, but the output is in a single line. Like this: . .. .bash_history .ssh updater_error_log.txt I need a built-in alternative to get filenames, each on a new line, like this: . .. .bash_history .ssh updater_error_log.txt 回答1: Use the -1 option (note this is a "one" digit, not a lowercase letter "L"), like this: ls -1a First, though, make sure your ls supports -1 . GNU coreutils (installed on standard Linux systems) and Solaris do; but