FAQ Database Discussion Community


Create a text file containing list of (relative paths to) files in a directory?

linux,ls
Suppose I am standing on a directory. Inside there's another directory called inside_dir containing a huge number of files. I want to create a file containing a list of all the files inside inside_dir, listed as the relative path to the files. That is, if there is a file called...

How to import latest database backup file to backup server

mysql,linux,ls,gunzip
I want to import the backup database file in *.sql.gz to my backup server. I try to use the follow command but there is an error with it ls -Art *.sql.gz | tail -n 1 | gunzip -c | mysql --user=user --password=password database gzip: stdin: not in gzip format So...

sas unix dirlist - how to read in file and last modified timestamp in yyyymmmdd:hh:ss format

unix,sas,ls
I am using the following code in UNIX SAS to try and read in the files from a folder: filename DIRLIST pipe 'dir "&path." ls -lt'; data dirlist ; length file $1000 ; infile dirlist length=reclen ; input file $varying256. reclen ; if index(file, '.txt')>=1; run; I do indeed manage...

how to read files listed by ls command one by one in bash?

linux,bash,ls
I want to read all the files in a particular directory, and I want to read it one by one. Here's what i've done so far. ls successfully get all the files from a specified directory, but could not give the file names to me one by one. It Echos...

Selective listing of files using ls

unix,grep,ls
I have a set of files in a directory named abc data.txthellohello1hello1.texthello.txt I want to list only the files hello and hello1. I tried using this command ls -lrt hello* | ls -lrt !(hello*.*) The output which I got is abcdata.txthellohello1 The pipe function is not working in this scenario....

list file key-pair sorted by time

linux,bash,sorting,ls,pair
I need to sort a filename pair sorted by time. Every file starts with AUSZUG or UMSATZ (and some numbers after). But the problem is that I cannot sort it by just time because some files can be uploaded (created) not as pair. For example, default sort: ls -ltr --time-style...

'tree' and 'ls' change text color on Linux command line

linux,terminal,tree,ls
I've been having a peculiar issue caused by the tree command on Linux. When I call tree, the the color of the command prompt changes, and is only returned to normal by the ls command. I'm curious if others have encountered the same issue, and if they have fixes or...

using 'ls' with options and folder and get full path

linux,unix,path,ls,pwd
i'm using ls myfolder and I've seen ls -lrt -d -1 $PWD/* which lists files with full path the question is how do i list files with full path in a folder? (without using cd to go inside that folder)...

What is the address from which /bin/ls program execution starts?

c,linux,unix,ls,bin
I need to know what's the address from which /bin/ls program execution starts (after dynamic linker fix the environment, what address gets the control?) I need it in hexadecimal (0xNNN...) or decimal format

Reading and listing objects in the order they appear in the source file in R

r,sorting,object,ls
I have a file with list of paths to URLs and and files that resembles the extract bellow: urls_queries_files.R url_some_dta <- "url_goes_here" backup_some_dta <- "path to the backup rds file goes here" url_exotic_dta <- "another_url" backup_exotic_dta <- "some backup rds file" url_mysterious_dta <- "url goes here" backup_mysterious_dta <- "backup rds...

Linux “ls -al” like program in C

c,linux,ls
I have for homework to write a C program, which is acting like the Linux "ls -al" command. I know that there are a lot of example programs over the internet, which are doing the thing that I need, but I have a specific problem, to which I can't find...

Identify and cbind multiple vectors based on vector name

r,vector,ls,cbind
I have 100 numeric vectors named sim1 to sim100 in my workspace, all of the same length (18). I'm trying to find a way to identify them and cbind them to create a data frame of 18 rows and 100 columns. I can easily create a character vector of length...

What does mean the @ (at) on unix access right?

php,unix,web,ls,access-rights
I have looked but it seems I did not found any question like mine. I would like to know what does mean the @ (at sign) on UNIX repository like as follow: MacBook-de-Blouz:twentyfifteen ratinahirana$ ll total 1136 -rwxrwxrwx@ 1 ratinahirana staff 376628 28 oct 2014 screenshot.png -rwxrwxrwx@ 1 ratinahirana staff...

UNIX - List files with a given suffix in order of last modification

unix,ls
I know I can use: for file in *.csv; do echo $file; done to list all the files the current directory with the supplied suffix. I also know I can use: ls -rt to list all the files in order of when they were modified with the most-recently-modified at the...

BASH : Difference between '-' and '--' options

linux,bash,shell,sh,ls
I was working my way through a primer on Shell (Bash) Scripting and had the following doubt : I came across the ls command The man page of ls lists a few use cases as : ls -a ls --block-size='M' My Question : What is the difference in - and...

List files that only have number in names

bash,file,numbers,find,ls
I have a directory with these files: 1.html 22.html 333.html zxc.html I want to get a list of the html files that only have digits in their name: 1.html 22.html 333.html I thought this would work find . -regex '^[0-9]+\.html' or ls -al | grep -E '^[0-9]+\.html$' But I get...

Linux - list all subdirectories and get ACL

linux,acl,ls
I am trying to: List all the subdirectories under a top level directory (/shared) and output this to a file called directory_list Afterwards I want to run getfacl using the file as input, and output the results to a file called acl_list So ultimately, getting the ACLs for all subdirectories...

Unix: Where does “ls -l” get comma-separated values in size field for devices?

c,unix,ls
When I run ls -l /dev on OS X I get an output with the following format (but many more files): crw-rw-rw- 1 root wheel 4, 126 Jun 11 20:28 ttywe crw-rw-rw- 1 root wheel 4, 127 Jun 11 20:28 ttywf As far as I can tell, it is specific...

Searching directories recursively for largest files in C

c,file,recursion,structure,ls
The goal of this program is to take a command line argument of a directory, and print the top 10 largest files under that directory (including subdirectories). So far, I am just trying to get it to print the files and their sizes recursively. I am using a structure to...

Concatenate file weight less than the sum of the files

filesize,cat,ls
I have done these commands to concatenate the files into one file: $ ls -1 | wc -l 16916 $ ls -1 *.txt | wc -l 16916 $ ls -lh | head -1 total 93M $ cat *.txt > ../nectar_3.txt $ ls -lh ../nectar_3.txt -rw-r--r-- 1 llopis llopis 52M May...

List only folders which matches the wildcard expression

wildcard,ls
Is there a command which lists all folders that matches a wildcard expression? Example, if there are thousands of directories and I only want those ending in M or those starting in JO to be listed, can I do that with a certain Linux command? Thanks!

Bash: Get modified `ls`-like output (multiple entries per line)

bash,multiple-columns,ls
When you call ls without additional options on the command line, you get multiple entries per line. Contrived example: $ ls mydir/*.tar.gz mydir/foo.tar.gz mydir/bar.tar.gz mydir/baz.tar.gz But if you want to modify the output in some way, you get one entry per line: $ ls mydir/*.tar.gz | sed "s/\.tar\.gz//g" mydir/foo mydir/bar...

“ls” works in cmd line but not in script for directories with space in their names

linux,bash,shell,ls
I am a beginner in bash scripting and I am trying to write a script which has as variables directory names, and who uses those variable values to run simple bash commands such as "ls" and "cd". It works perfectly fine when the directory has a "normal" name, for example...

How can I search for a file using tcl, with only part of the file name

regex,bash,foreach,tcl,ls
If I have a folder with the following files: hello-version-1-090.txt hello-awesome-well-091.txt goodday-087.txt hellooo-874.txt hello_476.txt hello_094.txt How can I search for a file which has the term: 'hello' and '091' in it using tcl. Possible solution: taking the output of an ls -l in a folder, splitting it with '\n' and...

In OSX with oh-my-zsh installed, how to highlight the output of `ls` in oh-my-zsh with Solarized theme installed

osx,ls,oh-my-zsh
I recently configured my terminal according to this blog. After followed it step by step, everything is OK but the colour of ls's outputs are grey. I googled this problem and found this. It says that adding export LSCOLORS=gxfxbEaEBxxEhEhBaDaCaD to the .bash_profile will resolve this problem. BUT, I use zsh...

How to exclude files using ls?

bash,ls
I'm using a python script I wrote to take some standard input from ls and load the data in the files described by that path. It looks something like this: ls -d /path/to/files/* | python read_files.py The files have a certain name structure based on what data they have in...

Show filename, date, size in shell

linux,shell,ls
I have a newbie question regarding linux command ls. How can I only show the filename(without the full path), the size of the file and the date? for example I want to show somehting like this: somehting.jpg 4096 04/05/2015 ...