LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 06-26-2013, 05:34 PM   #1
Kogami
LQ Newbie
 
Registered: Jun 2013
Distribution: Ubuntu 14.04 LTS
Posts: 21

Rep: Reputation: Disabled
Reducing Length of File Bath in BASH


Hey Guys,
First time here, but not the first time with Linux.

Occasionally I run into problems where I'll be working in deeply nested directories, and get directory paths like:

kogami@WorldPortal ~/Música/Classical Archive/Disks/Philips 55 Box/Beethoven Symphony 6 Pastoral and Violin Concerto/Symphony-6-Pastoral/

Is there anyway I can shorten the APPEARANCE of this path in my shell? If so, feel free to let me know. It can get in the way of certain file operations.

Regards,
Kogami
 
Old 06-26-2013, 09:02 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You need to edit the setting of $PS1 (aka prompt)
Try this
Code:
[\u@\h \W]\$
Note that this needs to be exported.
Its usually set in a login file; in my case (centos6.4) /etc/bashrc.
See this page for all the options http://www.cyberciti.biz/tips/howto-...up-prompt.html

Can I just mention that spaces in dir/file name is legal, BUT causes issues for cmds. Default in Linux is that input params to a cmd eg 'cd' are space separated, so I'd highly recommend using underscore or dash (as you have somewhat) instead.
 
Old 06-27-2013, 09:14 AM   #3
Kogami
LQ Newbie
 
Registered: Jun 2013
Distribution: Ubuntu 14.04 LTS
Posts: 21

Original Poster
Rep: Reputation: Disabled
Hi,
Thank you so much for the tip. I was able to resolve the issue simply by replacing the "w" with "W" in my current $PW1 configuration. That way I was able to keep all the colors and whatnot. And since you mentioned it, is there a bash script one could use to replace all of the spaces in directory and filenames with hypens "-"? That would be useful so I don't end up with shell related issues.

Thank you for all your help.

Regards,
Kogami
 
Old 07-01-2013, 01:23 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Pretty common request; lots of threads here at LQ and on google.
Here's one with a few methods http://stackoverflow.com/questions/1...the-file-names.
Do TEST carefully before using on live files (& of course have a backup first!)
 
  


Reply



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
[SOLVED] Bash script to read csv file with multiple length columns japena Linux - Newbie 17 07-27-2011 01:47 PM
bash/sed/awk fill each line in text file with space to fixed length khairil Programming 11 01-09-2008 05:28 AM
BASH length of file baks Programming 14 03-13-2007 09:52 PM
Zero-length bash .history file! revmyo Linux - Security 1 12-03-2005 08:09 PM
Bash scripting: column-ize file of varying length strings Quantum0726 Programming 4 08-13-2005 06:19 PM

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

All times are GMT -5. The time now is 10:21 AM.

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