LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-15-2014, 10:41 PM   #1
bastille77
LQ Newbie
 
Registered: Dec 2014
Location: San Jose
Distribution: Mint
Posts: 5

Rep: Reputation: Disabled
Alias to display file names of all hidden files in current directory not working


Hello Linux gurus,

I'm having some trouble in my attempt to create an alias for the following set of commands that shows the file name of all hidden files in the current directory:

ls -la | awk '$9 ~ /^\./ {print $9}'

It works fine when I type it in the command line. But when I put it in an alias like this:

alias .f='ls -la | awk '$9 ~ /^\./ {print $9}''

I encounter the following error message when I invoke the alias:
awk: fatal: cannot open file `/^./' for reading (No such file or directory)

I believe the placement of the first pair of single quotes is causing the error, as the shell treats everything in it as one argument and the regex pattern "/^./" as the argument for file name for awk. But I've no idea how to fix the broken syntax. I've tried using back-ticks, double quotes, all to no avail.

Any help is greatly appreciated.
 
Old 12-16-2014, 12:04 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,720

Rep: Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704
Hi,

the problem is that you are trying to nest single quotes. In this instance you might be better served by a function instead of an alias. However, have you considered using the following instead?
Code:
ls -ad1 .*
I think it does what you are looking for.

Evo2.
 
1 members found this post helpful.
Old 12-16-2014, 12:18 AM   #3
bastille77
LQ Newbie
 
Registered: Dec 2014
Location: San Jose
Distribution: Mint
Posts: 5

Original Poster
Rep: Reputation: Disabled
The code worked perfectly. Thanks!

I went for the complicated solution when a much simpler one is at hand.

Could you explain what the -1 option does in the ls command? I can't seem to find it in the man pages.
 
Old 12-16-2014, 12:37 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,720

Rep: Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704Reputation: 1704
Hi,
Quote:
Originally Posted by bastille77 View Post
I went for the complicated solution when a much simpler one is at hand.
There are many ways.
Quote:
Originally Posted by bastille77 View Post
Could you explain what the -1 option does in the ls command? I can't seem to find it in the man pages.
It's in the man page - it just means output only one file per line.

Evo2.
 
Old 12-16-2014, 12:42 AM   #5
bastille77
LQ Newbie
 
Registered: Dec 2014
Location: San Jose
Distribution: Mint
Posts: 5

Original Poster
Rep: Reputation: Disabled
Cool, thanks again for the help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display short names of directories those wrong name of directory or file? Webman12 Linux - Desktop 13 03-03-2020 11:37 PM
List file with path from current working directory Stragonian Linux - Newbie 3 10-09-2012 09:39 AM
[SOLVED] How do i grep file names in current directory? Rogue45 Linux - Newbie 10 09-07-2012 12:38 PM
Batch merging pairs of files in a directory to unique file names bonissen Linux - Newbie 5 11-29-2011 01:57 PM
SAMBA: display of share names is OK but files names are wrong superandrzej Linux - Software 5 02-02-2004 09:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration