ls

How to remove dir background in `ls -color` output

醉酒当歌 提交于 2019-12-20 02:37:20
问题 I use default Linux Mint .bashrc, here is full bashrc, the output is like: some dir has green background, How to remove it? 回答1: To remove all background colors, stick the following into your ~/.bashrc : eval "$(dircolors -p | \ sed 's/ 4[0-9];/ 01;/; s/;4[0-9];/;01;/g; s/;4[0-9] /;01 /' | \ dircolors /dev/stdin)" 回答2: The explanation is given in the output of dircolors -p , e.g., Of course dircolors doesn't color its output. I used this script: #!/usr/bin/perl -w use strict; our $comment = "

Listing the content of a tar file or a directory only down to some level

自闭症网瘾萝莉.ら 提交于 2019-12-18 10:03:54
问题 I wonder how to list the content of a tar file only down to some level? I understand tar tvf mytar.tar will list all files, but sometimes I would like to only see directories down to some level. Similarly, for the command ls , how do I control the level of subdirectories that will be displayed? By default, it will only show the direct subdirectories, but not go further. 回答1: tar tvf scripts.tar | awk -F/ '{if (NF<4) print }' drwx------ glens/glens 0 2010-03-17 10:44 scripts/ -rwxr--r-- glens

awk in bash with ls and variable

点点圈 提交于 2019-12-18 09:49:27
问题 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' 回答1: 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

ls with numeric range doesn't work inside bash script

筅森魡賤 提交于 2019-12-18 08:56:20
问题 I have a folder with files named as file_1.ext...file_90.ext . I can list a range of them with the following command: $ ls /home/rasoul/myfolder/file_{6..19}.ext but when I want to use this command inside a bash script, it doesn't work. Here is a minimal example: #!/bin/bash DIR=$1 st=$2 ed=$3 FILES=`ls ${DIR}/file\_\{$st..$ed\}.ext` for f in $FILES; do echo $f done running it as, $ bash test_script.sh /home/rasoul/myfolder 6 19 outputs the following error message: ls: cannot access /home

Count number of files within a directory in Linux? [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-17 21:37:45
问题 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 5 years ago . To count the number of files in a directory, I typically use ls directory | wc -l But is there another command that doesn't use wc ? 回答1: this is one: ls -l . | egrep -c '^-' Note: ls -1 | wc -l Which means: ls : list files in dir -1 : (that's a ONE) only one entry per line. Change it to -1a if you want hidden

Listing files in date order with spaces in filenames

ぐ巨炮叔叔 提交于 2019-12-17 20:16:40
问题 I am starting with a file containing a list of hundreds of files (full paths) in a random order. I would like to list the details of the ten latest files in that list. This is my naive attempt: $ ls -las -t `cat list-of-files.txt` | head -10 That works, so long as none of the files have spaces in, but fails if they do as those files are split up at the spaces and treated as separate files. File "hello world" gives me: ls: hello: No such file or directory ls: world: No such file or directory I

Unix ls command: show full path when using options

我的梦境 提交于 2019-12-17 17:25:44
问题 I often use this list command in Unix (AIX / KSH): ls -Artl It displays the files as this: -rw-r--r-- 1 myuser mygroup 0 Apr 2 11:59 test1.txt -rw-r--r-- 1 myuser mygroup 0 Apr 2 11:59 test2.txt I would like to modify the command such a way that the full path of the file is displayed. For example: -rw-r--r-- 1 myuser mygroup 0 Apr 2 11:59 /usr/test1.txt -rw-r--r-- 1 myuser mygroup 0 Apr 2 11:59 /usr/test2.txt Any ideas? I found several resolution methods using pwd or find but - as far as I

Iterate shell script over list of subdirectories

天涯浪子 提交于 2019-12-13 09:40:27
问题 I have a folder (let's call it folder1 that contains only subdirectories. I want to write a shell script that iterates several python scripts over each subdirectory. As it is, I have to type out the absolute path to each subdirectory within the script, but I want to be able to cd to folder1 and simply run the shell script from there and have it automatically iterate over the subdirectories, whatever their name or the location of folder1 . Current code (saved as shellscript.sh): #! /bin/sh

Parsing ls, not recommended

拟墨画扇 提交于 2019-12-13 08:59:40
问题 I received a advice for do not parse ls, like describes in this website: Don't parse ls. I was looking for DAILY files in my directory so that's what I did then: for f in *.DA*; do [[ -e $f ]] || continue for file in $f; do echo "The file that you are working on: "$file archiveContent=$( sed -n -e 1p $file ) echo $archiveContent done done Ok, that's works well, I've two files A.DAILY and B.DAILY, with the both archives I can get what is inside it, but when I changed a little bit the loop, it

C - error when attempting to pass /bin/ls to execvp

半腔热情 提交于 2019-12-13 04:44:24
问题 I am working on a C program that needs to be able to execute certain commands using execvp, and I have implemented this with: execvp(arguments[0], arguments); where arguments[] is an array of stings. For the most part, my implementation works fine - e.g. if arguments is {"touch", "somefile.txt"} then the touch command is called as expected. However, when I attempt to pass ls to execvp with arguments being something like {"/bin/ls", "-a", "."} , the ls function prints the directory listing as